#[non_exhaustive]pub struct RetryPolicy {
pub max_retries: u32,
pub initial_backoff: Duration,
pub multiplier: f64,
pub max_backoff: Duration,
pub jitter: bool,
}Expand description
How a retryable run is re-attempted: a bounded number of retries with exponential backoff, a per-delay cap, and optional full jitter.
Used two ways:
- Client-wide via
CliClient::default_retry— every verb of the client retries on a shared policy + classifier, instead of repeating a per-commandCommand::retry(which is fixed-backoff and per-call). - As the schedule behind
Command::retry, whose(max_attempts, backoff)form is the fixed-backoff special case (multiplier1.0, no growth, no jitter).
The n-th retry (0-based) waits min(initial_backoff × multiplier^n, max_backoff); with jitter the actual wait is a uniform
random value in [0, that] (AWS-style full jitter), which decorrelates a
fleet of clients all backing off at once. Jitter uses a small per-thread PRNG
seeded from system entropy — no extra dependency, and no crypto-grade
randomness is needed for backoff.
Distinct from RestartPolicy: a RetryPolicy replays
a verb to success (re-running on a classified Error), while a
RestartPolicy is the Supervisor’s keep-alive restart
schedule for a long-lived process — different subsystems, different intent.
Non-exhaustive: construct via RetryPolicy::new / Default + the builder
methods (new knobs can be added without a breaking change). Intentionally
not Copy — that would pin every future field to a Copy type (a boxed
custom-backoff fn, a list of retryable codes), and shedding Copy later is the
breaking change; Clone covers every real need (all reads are by-&).
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.max_retries: u32Retries after the first attempt — 0 never retries; 3 (the default)
means up to 4 total attempts. Counts retries (like
Supervisor::max_restarts), not total
attempts — in contrast to Command::retry’s
max_attempts.
initial_backoff: DurationBackoff before the first retry (and the whole delay when multiplier
is 1.0). Default 100 ms. Duration::ZERO retries immediately. (The
base of Supervisor::backoff, spelled in
full here.)
multiplier: f64Exponential growth factor per retry. Default 2.0; 1.0 is fixed backoff.
Values below 1.0 (or non-finite) are treated as 1.0 (backoff never
shrinks). (The factor of Supervisor::backoff.)
max_backoff: DurationUpper bound on a single delay, so exponential growth can’t run away.
Default 30 s; set Duration::MAX to effectively disable the cap.
jitter: boolApply full jitter — spread the actual wait uniformly over [0, delay],
so a retry may fire almost immediately (AWS-style; decorrelates a fleet all
backing off at once). This is full jitter, distinct from the multiplicative
band the supervisor’s RestartPolicy backoff uses.
Default true.
Implementations§
Source§impl RetryPolicy
impl RetryPolicy
Sourcepub fn new() -> Self
pub fn new() -> Self
A policy with the default schedule (3 retries, 100 ms initial, ×2 growth, 30 s cap, jitter on). Tune with the builder methods.
Sourcepub fn max_retries(self, retries: u32) -> Self
pub fn max_retries(self, retries: u32) -> Self
Set the number of retries after the first attempt (0 disables retrying).
Sourcepub fn initial_backoff(self, backoff: Duration) -> Self
pub fn initial_backoff(self, backoff: Duration) -> Self
Set the backoff before the first retry (the base of the exponential).
Sourcepub fn multiplier(self, multiplier: f64) -> Self
pub fn multiplier(self, multiplier: f64) -> Self
Set the exponential growth factor (1.0 = fixed backoff).
Sourcepub fn max_backoff(self, max: Duration) -> Self
pub fn max_backoff(self, max: Duration) -> Self
Cap a single delay at max (after growth, before jitter).
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