pub struct RetryPolicy {
pub max_retries: u32,
pub backoff_initial: Duration,
pub backoff_max: Duration,
pub backoff_jitter: f64,
pub http_statuses: BTreeSet<u16>,
pub respect_retry_after: bool,
pub max_retry_after: Duration,
pub retry_connection_errors: bool,
pub retry_timeouts: bool,
pub total_budget: Option<Duration>,
}Expand description
Configuration for retry behavior.
All fields are public. The Default value matches the SPEC and both
official SDKs.
use std::time::Duration;
use typesafe_system_one::{Client, RetryPolicy};
let client = Client::builder()
.api_key("key")
.retry_policy(RetryPolicy {
max_retries: 3,
total_budget: Some(Duration::from_secs(10)),
..Default::default()
})
.build()
.unwrap();Fields§
§max_retries: u32Maximum retries after the initial attempt; 0 disables retries.
backoff_initial: DurationFirst backoff delay, doubled each retry up to Self::backoff_max;
zero disables backoff.
backoff_max: DurationMaximum backoff delay; zero disables backoff.
backoff_jitter: f64Fraction of each backoff delay randomly subtracted; between 0 and 1.
http_statuses: BTreeSet<u16>HTTP status codes that are retried.
respect_retry_after: boolWhether to honor retry-after-ms and Retry-After headers.
max_retry_after: DurationMaximum honored server retry delay; a longer delay falls back to backoff.
retry_connection_errors: boolWhether to retry connection errors (no HTTP response at all).
retry_timeouts: boolWhether to retry attempts that exceeded the per-attempt timeout.
total_budget: Option<Duration>Retry budget per call, measured from the first attempt; None or
Some(Duration::ZERO) disables it.
A retry is not started when the elapsed time plus its delay would
reach or exceed the budget; the call then returns the last real
error rather than an artificial timeout, so the caller sees the
actual 529. An attempt that has started runs to its own per-attempt
timeout, so a call can overrun the budget by up to one timeout (the
same semantics as the official Python SDK). For a hard bound, wrap
the call in tokio::time::timeout.
Implementations§
Source§impl RetryPolicy
impl RetryPolicy
Sourcepub fn is_retryable_status(&self, status: u16) -> bool
pub fn is_retryable_status(&self, status: u16) -> bool
Whether an HTTP status is retried under this policy.
Sourcepub fn backoff_delay(&self, retry_number: u32, random: f64) -> Duration
pub fn backoff_delay(&self, retry_number: u32, random: f64) -> Duration
The pure backoff portion of the delay for retry retry_number
(0-based), given a jitter random value in [0, 1).