Coffrify.Runtime.Retry (Coffrify v0.9.0)

View Source

Pluggable retry policies used by Coffrify.Client and exposed for user code.

Built-in implementations:

A policy is any term whose module implements the Policy behaviour. The client calls Policy.next/3 with the current attempt number and the request context (status, error reason, parsed Retry-After).

Summary

Types

Per-request context handed to the policy.

Decision returned by a retry policy.

Functions

Apply jitter symmetrically around base by the given fraction.

Invoke a policy. policy is any struct implementing the Policy behaviour.

Parse an HTTP Retry-After header (seconds OR HTTP-date) into ms. Returns nil when the header is missing or malformed.

Types

context()

@type context() :: %{
  optional(:status) => non_neg_integer(),
  optional(:error_reason) => atom() | term(),
  optional(:retry_after_ms) => non_neg_integer() | nil
}

Per-request context handed to the policy.

decision()

@type decision() :: %{should_retry: boolean(), delay_ms: non_neg_integer()}

Decision returned by a retry policy.

Functions

jitter(base, factor \\ 0.2)

@spec jitter(non_neg_integer(), float()) :: non_neg_integer()

Apply jitter symmetrically around base by the given fraction.

next(policy, attempt, ctx)

@spec next(struct(), non_neg_integer(), context()) :: decision()

Invoke a policy. policy is any struct implementing the Policy behaviour.

parse_retry_after(value)

@spec parse_retry_after(String.t() | nil) :: non_neg_integer() | nil

Parse an HTTP Retry-After header (seconds OR HTTP-date) into ms. Returns nil when the header is missing or malformed.