Retry logic with configurable backoff strategies.
Wraps a function call and retries on failure according to the configured strategy. Does not use a GenServer -- retry is stateless per-call.
Options
:name-- optional atom used in telemetry metadata. Default:retry.:max_attempts-- total attempts (including the first). Default3.:backoff-- backoff strategy (:fixed,:linear,:exponential). Default:exponential.:base_delay-- base delay in ms. Default100.:max_delay-- cap on delay in ms. Default10_000.:jitter-- jitter setting. Can betrue(full jitter, delay randomized in[0, delay]),false(no jitter), or a float between 0.0 and 1.0 for proportional jitter (delay adjusted by +/-delay * fraction). Defaulttrue.:retry_on-- 1-arity predicate that returnstrueif the result should be retried. Default: retries{:error, _}and:error. Takes precedence over:error_classifierwhen both are provided.:error_classifier-- module implementingExResilience.ErrorClassifier. When provided (and:retry_onis not), retries results classified as:retriable. Ignored if:retry_onis also set.
Examples
iex> ExResilience.Retry.call(fn -> {:ok, 42} end, max_attempts: 3)
{:ok, 42}
iex> ExResilience.Retry.call(fn -> {:error, :fail} end, max_attempts: 2)
{:error, :fail}
Summary
Functions
Executes fun with retry logic.
Types
@type option() :: {:name, atom()} | {:max_attempts, pos_integer()} | {:backoff, ExResilience.Backoff.strategy()} | {:base_delay, ExResilience.Backoff.milliseconds()} | {:max_delay, ExResilience.Backoff.milliseconds()} | {:jitter, boolean() | float()} | {:retry_on, (term() -> boolean())} | {:error_classifier, module()}