pub struct RetryPolicy {
pub max_attempts: u32,
pub initial_delay: Duration,
pub max_delay: Duration,
pub backoff_factor: f64,
pub jitter: f64,
pub retry_on: RetryOn,
}Expand description
How many times a node is attempted, and how long between attempts.
Fields§
§max_attempts: u32Total attempts, including the first. 1 means no retry.
initial_delay: DurationDelay before the second attempt.
max_delay: DurationCeiling on any single delay.
backoff_factor: f64Multiplier applied to the delay after each attempt.
jitter: f64Fraction of the delay to vary randomly, so retries from many nodes do not
align. 0.0 is exact, 1.0 varies the delay across its whole width.
retry_on: RetryOnWhich failures to retry.
Implementations§
Source§impl RetryPolicy
impl RetryPolicy
Sourcepub fn new(max_attempts: u32) -> Self
pub fn new(max_attempts: u32) -> Self
A policy allowing max_attempts in total, with the other defaults.
Sourcepub fn with_initial_delay(self, delay: Duration) -> Self
pub fn with_initial_delay(self, delay: Duration) -> Self
Set the delay before the second attempt.
Sourcepub fn with_max_delay(self, delay: Duration) -> Self
pub fn with_max_delay(self, delay: Duration) -> Self
Set the ceiling on any single delay.
Sourcepub fn with_backoff_factor(self, factor: f64) -> Self
pub fn with_backoff_factor(self, factor: f64) -> Self
Set the multiplier applied after each attempt.
Sourcepub fn with_jitter(self, jitter: f64) -> Self
pub fn with_jitter(self, jitter: f64) -> Self
Set how much the delay varies randomly, as a fraction of itself.
Sourcepub fn with_retry_on(self, retry_on: RetryOn) -> Self
pub fn with_retry_on(self, retry_on: RetryOn) -> Self
Set which failures to retry.
Sourcepub fn allows_another_attempt(&self, attempts_so_far: u32) -> bool
pub fn allows_another_attempt(&self, attempts_so_far: u32) -> bool
Whether another attempt is allowed after attempts_so_far failures.
Sourcepub fn delay_for_attempt(&self, attempt: u32) -> Duration
pub fn delay_for_attempt(&self, attempt: u32) -> Duration
The delay before attempt number attempt, counting the first attempt as
zero, so delay_for_attempt(1) precedes the second attempt.
The delay grows by backoff_factor each time, is clamped to max_delay,
and is then varied by up to jitter of itself. A backoff_factor at or
below zero is treated as 1.0, giving a constant delay rather than
collapsing to nothing.
The clamp happens before the jitter, so a jittered delay can sit slightly
above max_delay only when jitter is positive; with jitter at zero the
ceiling is exact.
Trait Implementations§
Source§impl Clone for RetryPolicy
impl Clone for RetryPolicy
Source§impl Debug for RetryPolicy
impl Debug for RetryPolicy
Source§impl Default for RetryPolicy
Ten attempts, one second of initial delay, doubling to a sixty-second cap.
impl Default for RetryPolicy
Ten attempts, one second of initial delay, doubling to a sixty-second cap.
The nine sleeps between ten attempts total about 243 seconds, so a node that
keeps failing takes roughly four minutes to give up, plus the time each attempt
itself takes. Lower max_attempts where a caller is waiting.
Attaching no policy at all is still one attempt: this default applies only to a policy you construct.