Immutable, JSON-safe retry timing for durable task work.
A policy is an exact, finite list of delays. Entry zero is used for the first retry requested by an executor, entry one for the second, and so on. Persisting the expanded list keeps scheduling deterministic across releases and restarts; no runtime callback is re-evaluated after recovery.
The empty policy returned by none/0 is the default and never retries.
Retry delays bound application-requested retries only. Re-delivery after an
ambiguous runner or node failure remains part of the runner's at-least-once
recovery contract and does not consume this list.
Summary
Functions
Expands a capped exponential policy into exact persisted delays.
Builds an exponential policy or raises ArgumentError.
Builds retries entries with one fixed delay.
Builds a fixed-delay policy or raises ArgumentError.
Decodes and validates a persistence map produced by to_map/1.
Builds a policy from its exact retry delays.
Builds an exact-delay policy or raises ArgumentError.
Returns the next persisted delay without modifying the policy.
Returns the default policy, which never retries executor outcomes.
Encodes a policy as a stable JSON-safe persistence map.
Validates a policy constructed locally or decoded by an adapter.
Types
@type delay_ms() :: non_neg_integer()
@type t() :: %Snodo.Extensions.Tasks.RetryPolicy{delays_ms: [delay_ms()]}
Functions
@spec exponential(delay_ms(), non_neg_integer(), keyword()) :: {:ok, t()} | {:error, term()}
Expands a capped exponential policy into exact persisted delays.
:max_delay_ms defaults to the largest portable timer delay supported by
this package. The first retry uses initial_delay_ms, then each subsequent
entry doubles until the cap is reached.
@spec exponential!(delay_ms(), non_neg_integer(), keyword()) :: t()
Builds an exponential policy or raises ArgumentError.
@spec fixed(delay_ms(), non_neg_integer()) :: {:ok, t()} | {:error, term()}
Builds retries entries with one fixed delay.
@spec fixed!(delay_ms(), non_neg_integer()) :: t()
Builds a fixed-delay policy or raises ArgumentError.
Decodes and validates a persistence map produced by to_map/1.
Builds a policy from its exact retry delays.
Builds an exact-delay policy or raises ArgumentError.
@spec next_delay(t(), non_neg_integer()) :: {:ok, delay_ms()} | :exhausted
Returns the next persisted delay without modifying the policy.
@spec none() :: t()
Returns the default policy, which never retries executor outcomes.
Encodes a policy as a stable JSON-safe persistence map.
Validates a policy constructed locally or decoded by an adapter.