Shared retry logic for Arcanum adapters.
Provides exponential backoff and a generic retry wrapper that adapters use for transient HTTP errors.
Summary
Functions
Sleeps for an exponentially increasing duration.
Returns the maximum number of retry attempts.
Executes fun with retry on specified status codes.
Functions
@spec backoff(pos_integer()) :: :ok
Sleeps for an exponentially increasing duration.
Formula: min(2s * 2^(attempt-1), 30s)
@spec max_attempts() :: pos_integer()
Returns the maximum number of retry attempts.
Executes fun with retry on specified status codes.
fun must return the standard {:ok, response} | {:error, reason} tuple.
The opts keyword list supports:
:retriable_statuses— list of HTTP status codes to retry on (required):on_success—fn response -> resultfor status 200 (required):on_error—fn status, body -> resultfor non-retriable errors (required):max_attempts— override default max attempts (optional)
On exhaustion, returns {:error, {:api_error, :max_retries_exceeded, last_status, last_body}}
where last_status and last_body are from the final failed attempt.