Wise.Internal.Retry (Wise v1.0.0)

Copy Markdown View Source

Exponential back-off retry with full jitter.

Uses :crypto.strong_rand_bytes/1 for cryptographically safe jitter. Retries on HTTP 429 and 5xx. Does not retry 4xx (except 429).

Summary

Types

opts()

@type opts() :: %{
  max_retries: non_neg_integer(),
  base_delay_ms: pos_integer(),
  max_delay_ms: pos_integer()
}

Functions

with_retry(fun, opts \\ %{base_delay_ms: 500, max_delay_ms: 30000, max_retries: 3})

@spec with_retry(
  (non_neg_integer() -> {:ok, any()} | {:error, Wise.Error.t()}),
  opts()
) ::
  {:ok, any()} | {:error, Wise.Error.t()}

Executes fun with retry logic.

fun must return {:ok, result} or {:error, Wise.Error.t()}.