Skip to main content

RetryPolicy

Struct RetryPolicy 

pub struct RetryPolicy {
    pub attempts: u32,
    pub initial: Duration,
    pub factor: f64,
    pub max: Duration,
    pub jitter: bool,
    pub max_elapsed: Option<Duration>,
    pub non_retryable: Vec<String>,
    pub retry_if: Option<RetryIf>,
    pub on_exhausted: Option<Exhausted>,
}
Expand description

How a failing step is retried. Attempts include the first one.

A failure marked final (Failure::fatal, or retryable: false) is never retried, whatever the policy says.

Fields§

§attempts: u32§initial: Duration§factor: f64§max: Duration§jitter: bool

Each delay is drawn between half of it and all of it, so retries of many runs that failed together spread out. On by default. The delay taken is recorded, so a replay waits for the same time.

§max_elapsed: Option<Duration>

No retry starts later than this after the step’s first failure.

§non_retryable: Vec<String>

Failures of these types (or caused by them) are not retried.

§retry_if: Option<RetryIf>

Called for each failure that could be retried; false makes it final.

§on_exhausted: Option<Exhausted>

When retries run out; None takes the engine’s (Config::on_exhausted, else fail).

Implementations§

§

impl RetryPolicy

pub fn none() -> Self

Run once; a failure is final.

pub fn exponential(attempts: u32, initial: Duration, max: Duration) -> Self

attempts tries with exponential backoff from initial, capped at max.

pub fn attempts(attempts: u32) -> Self

attempts tries with the default backoff.

pub fn no_jitter(self) -> Self

Without jitter: each delay is exactly the backoff.

pub fn max_elapsed(self, limit: Duration) -> Self

No retry starts later than limit after the first failure.

pub fn non_retryable(self, kind: impl Into<String>) -> Self

Failures of type kind (or caused by one) are final.

pub fn retry_if( self, f: impl Fn(&Failure, u32) -> bool + Send + Sync + 'static, ) -> Self

f(failure, attempt) decides whether each failure is retried.

pub fn on_exhausted(self, then: Exhausted) -> Self

What the step does when its retries run out (Exhausted::Pause: the run waits for a resume).

pub fn allows(&self, failure: &Failure, attempt: u32) -> bool

Whether failure, from attempt attempt, may be retried.

pub fn retryable(&self, failure: &Failure, attempt: u32) -> bool

Whether failure is one the policy retries at all (not final), whatever attempts remain.

pub fn delay(&self, failed_attempt: u32) -> Duration

Trait Implementations§

§

impl Clone for RetryPolicy

§

fn clone(&self) -> RetryPolicy

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
§

impl Debug for RetryPolicy

§

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

Formats the value using the given formatter. Read more
§

impl Default for RetryPolicy

§

fn default() -> Self

Three attempts, about 100 ms then 200 ms apart (with jitter).

§

impl PartialEq for RetryPolicy

§

fn eq(&self, o: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

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, 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> Same for T

Source§

type Output = T

Should always be Self
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.