Retry adapter backed by Foundation retry policies.
This adapter provides:
- Full retry orchestration via
with_retry/2 - Opt-in
:retry_budget_msstops before a delay would reach the total call budget and returns the last result, including time spent in the initial attempt. - HTTP-specific retry determination via
should_retry?/1 - Retry-After header parsing via
parse_retry_after/1 - Optional
Pristine.Cancellationintegration that interrupts the default retry wait and prevents later attempts once cancellation is terminal.
When a caller supplies a custom :sleep_fun, Pristine preserves that hook.
Cancellation is checked immediately before and after the custom sleeper; a
sleeper that blocks internally must cooperate with the same cancellation token
if it needs mid-sleep interruption.
Summary
Functions
Create a retry policy with HTTP-aware retry-after support.
Parse retry delay from HTTP response headers.
Determine if an HTTP response should be retried.
Functions
@spec http_aware_policy(keyword()) :: Foundation.Retry.Policy.t()
Create a retry policy with HTTP-aware retry-after support.
This function creates a retry policy that will respect Retry-After headers from HTTP responses. Use this when you need the retry delays to be driven by server-specified delays.
Options
All standard Foundation.Retry.Policy options, plus:
:response_headers_fun- Function to extract headers from the result
Examples
policy = Foundation.http_aware_policy(
max_attempts: 5,
response_headers_fun: fn
{:ok, %{headers: headers}} -> headers
_ -> %{}
end
)
Parse retry delay from HTTP response headers.
Delegates to Foundation.Retry.HTTP.parse_retry_after/1.
Examples
iex> Pristine.Adapters.Retry.Foundation.parse_retry_after(%{"retry-after" => "5"})
5000
Determine if an HTTP response should be retried.
Delegates to Foundation.Retry.HTTP.should_retry?/1.
Examples
iex> Pristine.Adapters.Retry.Foundation.should_retry?(%{status: 429})
true
iex> Pristine.Adapters.Retry.Foundation.should_retry?(%{
...> status: 400,
...> headers: %{"x-should-retry" => "true"}
...> })
true