Skip to main content

RetryPolicy

Struct RetryPolicy 

Source
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: u32

Total attempts, including the first. 1 means no retry.

§initial_delay: Duration

Delay before the second attempt.

§max_delay: Duration

Ceiling on any single delay.

§backoff_factor: f64

Multiplier applied to the delay after each attempt.

§jitter: f64

Fraction 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: RetryOn

Which failures to retry.

Implementations§

Source§

impl RetryPolicy

Source

pub fn new(max_attempts: u32) -> Self

A policy allowing max_attempts in total, with the other defaults.

Source

pub fn with_initial_delay(self, delay: Duration) -> Self

Set the delay before the second attempt.

Source

pub fn with_max_delay(self, delay: Duration) -> Self

Set the ceiling on any single delay.

Source

pub fn with_backoff_factor(self, factor: f64) -> Self

Set the multiplier applied after each attempt.

Source

pub fn with_jitter(self, jitter: f64) -> Self

Set how much the delay varies randomly, as a fraction of itself.

Source

pub fn with_retry_on(self, retry_on: RetryOn) -> Self

Set which failures to retry.

Source

pub fn allows_another_attempt(&self, attempts_so_far: u32) -> bool

Whether another attempt is allowed after attempts_so_far failures.

Source

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

Source§

fn clone(&self) -> RetryPolicy

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for RetryPolicy

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

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.

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more