Retry policy: wrap an operation in a bounded-attempt loop with configurable backoff and error-matching.
Three constructors:
exponential/1-- exponential backoff (base_ms * 2^(attempt - 1), capped atmax_ms)linear/1-- fixedbase_msbetween attemptsalways/1-- exponential backoff, retry on any{:error, _}
Fields
max_attempts-- total attempts including the first; must be>= 1base_ms-- base delay in ms between attemptsmax_ms-- cap on the computed backoff (base_ms * 2^(attempt - 1)for exponential; ignored forlinear); default:infinitymode--:exponential | :linear; affects backoff computationon-- error matcher::any-- retry on any{:error, _}(the default foralways/1)- list of atoms -- retry on
{:error, atom}whenatomis in the list - list of
{Module, atom}tuples -- retry on{:error, {Module, atom}} - a
(reason -> boolean)predicate -- arbitrary matching
Summary
Functions
Construct an "always retry" policy: exponential backoff with
:on set to :any.
Backoff in ms before the given attempt (1-indexed: backoff/1 is the delay before the second attempt).
Construct an exponential-backoff retry policy.
Construct a linear-backoff retry policy. :base_ms is the
delay between attempts (no exponential growth).
Check whether reason matches the policy's :on matcher.
Types
@type mode() :: :exponential | :linear
@type t() :: %Raxol.Agent.Policy.Retry{ base_ms: non_neg_integer(), max_attempts: pos_integer(), max_ms: non_neg_integer() | :infinity, mode: mode(), on: matcher() }
Functions
Construct an "always retry" policy: exponential backoff with
:on set to :any.
@spec backoff(t(), pos_integer()) :: non_neg_integer()
Backoff in ms before the given attempt (1-indexed: backoff/1 is the delay before the second attempt).
Construct an exponential-backoff retry policy.
Required: :max_attempts, :base_ms. Optional: :max_ms, :on.
Construct a linear-backoff retry policy. :base_ms is the
delay between attempts (no exponential growth).
Check whether reason matches the policy's :on matcher.