Arcanum.Retry (arcanum v0.1.4)

Copy Markdown View Source

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

backoff(attempt)

@spec backoff(pos_integer()) :: :ok

Sleeps for an exponentially increasing duration.

Formula: min(2s * 2^(attempt-1), 30s)

max_attempts()

@spec max_attempts() :: pos_integer()

Returns the maximum number of retry attempts.

with_retry(opts, fun)

@spec with_retry(
  keyword(),
  (-> {:ok, map()} | {:error, term()})
) :: term()

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_successfn response -> result for status 200 (required)
  • :on_errorfn status, body -> result for non-retriable errors (required)
  • :max_attempts — override default max attempts (optional)