pub struct RetryPolicy {
pub max_retries: usize,
pub initial_delay: Duration,
pub max_delay: Duration,
pub backoff_multiplier: f64,
pub jitter: f64,
pub retry_on: RetryOn,
}Expand description
Policy controlling RetryingChatClient backoff.
Delays grow exponentially from initial_delay by
backoff_multiplier per attempt, are capped at
max_delay, and are then reduced by up to
jitter (a fraction of the delay). When the failing error
carries a server Retry-After (see Error::retry_after) that value is
used instead of the computed backoff (still capped by max_delay, and not
jittered — it is an explicit server instruction).
Fields§
§max_retries: usizeMaximum number of retries after the initial attempt (default 3, so
up to four total attempts).
initial_delay: DurationBase delay before the first retry (default 500ms).
max_delay: DurationUpper bound on any single delay, also capping a server Retry-After
(default 30s).
backoff_multiplier: f64Exponential growth factor applied per retry (default 2.0).
jitter: f64Jitter as a fraction in 0.0..=1.0 (default 0.3): the computed delay
is multiplied by 1 - jitter * r for a per-attempt random r in
[0, 1). 0.0 disables jitter (fully deterministic delays).
retry_on: RetryOnWhich errors to retry (default RetryOn::Default).
Implementations§
Source§impl RetryPolicy
impl RetryPolicy
Sourcepub fn with_max_retries(max_retries: usize) -> RetryPolicy
pub fn with_max_retries(max_retries: usize) -> RetryPolicy
A policy with the given retry count and otherwise-default backoff.
Sourcepub fn initial_delay(self, delay: Duration) -> RetryPolicy
pub fn initial_delay(self, delay: Duration) -> RetryPolicy
Set the base delay before the first retry.
Sourcepub fn max_delay(self, delay: Duration) -> RetryPolicy
pub fn max_delay(self, delay: Duration) -> RetryPolicy
Set the per-delay cap (also caps a server Retry-After).
Sourcepub fn backoff_multiplier(self, multiplier: f64) -> RetryPolicy
pub fn backoff_multiplier(self, multiplier: f64) -> RetryPolicy
Set the exponential growth factor.
Sourcepub fn jitter(self, jitter: f64) -> RetryPolicy
pub fn jitter(self, jitter: f64) -> RetryPolicy
Set the jitter fraction (clamped to 0.0..=1.0).
Sourcepub fn retry_on(self, retry_on: RetryOn) -> RetryPolicy
pub fn retry_on(self, retry_on: RetryOn) -> RetryPolicy
Set the retryability rule.
Trait Implementations§
Source§impl Clone for RetryPolicy
impl Clone for RetryPolicy
Source§fn clone(&self) -> RetryPolicy
fn clone(&self) -> RetryPolicy
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more