Skip to main content

RetryPolicy

Struct RetryPolicy 

Source
pub struct RetryPolicy {
    pub max_attempts: u32,
    pub initial_backoff: Duration,
    pub max_backoff: Duration,
    pub multiplier: u32,
    pub jitter: bool,
    pub max_advice: Duration,
}
Expand description

How many times to repeat a failed effect, and how far apart.

The defaults are safe rather than timid: three attempts with exponential backoff. They are safe because Disposition gates them — an effect whose failure is in-doubt is not repeated under this policy unless its Recovery permits guessing, no matter what max_attempts says.

Fields§

§max_attempts: u32

Total attempts including the first. 1 means “never repeat”.

§initial_backoff: Duration

Delay before the second attempt.

§max_backoff: Duration

Ceiling on the delay, however many attempts have passed.

Also the bound on how long one effect holds a worker — see the module docs. For waits longer than a few seconds, the run should suspend instead: that is StepCtx::sleep, not a retry policy.

§multiplier: u32

Growth factor per attempt. An integer, so the schedule is exactly reproducible on any platform without depending on float rounding.

§jitter: bool

Whether to spread the delay across runs. See the module docs — this is derived from a hash, not drawn from an RNG.

§max_advice: Duration

The longest this run will wait because a peer named a time.

A separate ceiling from max_backoff, because the two bound different risks. max_backoff bounds a guess: nobody knows when the service recovers, so waiting long is waste. This bounds somebody else’s word — a Retry-After from the one party with an interest in never being called again — and the number that makes the wait useful is theirs, not ours. Sharing one ceiling would mean either guessing for as long as a peer may demand, or discarding advice that is merely longer than a guess would have been.

A minute covers every published provider rate-limit window and is short enough that a hostile or broken value costs one wasted minute of one worker. Advice past it is clamped, not discarded: waiting part of a window is closer to right than ignoring it, and if the window really was longer the next refusal names what is left.

Raising it holds a worker for that long. A rate limit measured in more than minutes is not a retry at all — that is StepCtx::sleep, which costs a row.

Implementations§

Source§

impl RetryPolicy

Source

pub const fn never() -> Self

Never repeat. The first failure is final.

The right choice for an effect that is expensive, externally rate limited, or whose driver already retries internally — a policy stacked on a driver that retries is a multiplication, not an addition.

Source

pub fn attempts(n: u32) -> Self

n total attempts with the default backoff schedule.

Source

pub fn with_backoff(self, initial: Duration, max: Duration) -> Self

Replace the backoff schedule, keeping the attempt count.

Source

pub fn without_jitter(self) -> Self

Turn jitter off, making the schedule identical across runs.

Source

pub const fn wait_at_most(self, advice: Duration) -> Self

Change how long a peer’s own Retry-After may hold a worker.

See max_advice for why this is not max_backoff.

Source

pub fn wait_before( &self, run: RunId, key: EffectKey, attempt: u32, advice: Option<Duration>, ) -> Duration

How long to wait before attempt, given whatever the peer said.

advice wins when present, clamped to max_advice, including when it is shorter than the computed backoff: the peer is describing its own recovery, and waiting longer than it asked buys nothing.

Source

pub fn permits(&self, attempt: u32) -> bool

Whether another attempt is left after attempt has failed.

attempt is 1-based, matching what the journal records.

Source

pub fn backoff(&self, run: RunId, key: EffectKey, attempt: u32) -> Duration

How long to wait before attempt (1-based; attempt 1 never waits).

Exponential with an integer multiplier and a ceiling, then optionally spread by a hash-derived factor in [0.5, 1.0] of the computed delay. Halving rather than scaling from zero keeps a floor under the schedule: full jitter can pick a near-zero delay and hammer a service that is already struggling.

Trait Implementations§

Source§

impl Clone for RetryPolicy

Source§

fn clone(&self) -> Self

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 Copy for RetryPolicy

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

Source§

fn default() -> Self

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

impl<'de> Deserialize<'de> for RetryPolicy

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Eq for RetryPolicy

Source§

impl PartialEq for RetryPolicy

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl Serialize for RetryPolicy

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for RetryPolicy

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> AsOut<T> for T
where T: Copy,

Source§

fn as_out(&mut self) -> Out<'_, T>

Returns an out reference to self.
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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

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

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<Unshared, Shared> IntoShared<Shared> for Unshared
where Shared: FromUnshared<Unshared>,

Source§

fn into_shared(self) -> Shared

Creates a shared type from an unshared type.
Source§

impl<T> MaybeSend for T
where T: Send,

Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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 = !

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

fn try_from(value: U) -> Result<T, !>

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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