Retry policy for Glean requests.
This is a thin policy struct that translates into Req retry options. Req
already implements exponential backoff with jitter and honours the
Retry-After header on HTTP 429 and 503 responses, so there is nothing to
reimplement here.
Defaults
Glean's APIs are overwhelmingly POST, including reads such as /search and
/chat. Req's default policy (:safe_transient) only retries GET and
HEAD, which would leave nearly every Glean call unretried, so the default
here is :transient.
Retried conditions come from Req: HTTP 408, 429, 500, 502, 503 and 504, and
transport errors such as timeouts, refused connections and closed sockets.
Examples
# No retries at all.
Gleanex.Retry.disabled()
# More attempts, fixed one second delay.
%Gleanex.Retry{max_retries: 5, delay: fn _count -> 1_000 end}
# Only retry rate limits, never server errors.
%Gleanex.Retry{retry: fn _req, %{status: status} -> status == 429 end}
Summary
Types
@type t() :: %Gleanex.Retry{ delay: nil | (non_neg_integer() -> non_neg_integer()), log_level: Logger.level() | false, max_retries: non_neg_integer(), retry: :transient | :safe_transient | false | (term(), term() -> boolean() | {:delay, pos_integer()}) }