pub struct RetryPolicy {
pub max_attempts: u32,
pub initial_backoff: Duration,
pub max_backoff: Duration,
pub max_total_delay: Duration,
}Expand description
How a client spaces out the attempts of a single send.
The delay before a retry doubles from RetryPolicy::initial_backoff and is capped by
RetryPolicy::max_backoff; the actual delay is then drawn anywhere between zero and that
ceiling, so that emitters which failed at the same moment do not come back at the same moment.
Retrying stops as soon as the delays of the send would add up to more than
RetryPolicy::max_total_delay.
Fields§
§max_attempts: u32Attempts a single send makes at most, the first one included. 1 disables retrying.
Never more than MAX_ATTEMPTS_CAP, and never less than one.
initial_backoff: DurationCeiling of the delay before the first retry.
max_backoff: DurationCeiling no single delay ever exceeds, however many retries were made.
max_total_delay: DurationBudget all the delays of one send share.
Implementations§
Source§impl RetryPolicy
impl RetryPolicy
Sourcepub const fn disabled() -> Self
pub const fn disabled() -> Self
A policy that never retries: one attempt, and the caller hears about whatever it returned.
Sourcepub fn attempts(&self) -> u32
pub fn attempts(&self) -> u32
Attempts this policy actually makes: RetryPolicy::max_attempts, brought back inside
1..=MAX_ATTEMPTS_CAP.
Sourcepub fn backoff_ceiling(&self, retry: u32) -> StdDuration
pub fn backoff_ceiling(&self, retry: u32) -> StdDuration
Ceiling of the delay before retry number retry, where 1 is the first retry.
It doubles from RetryPolicy::initial_backoff and never exceeds
RetryPolicy::max_backoff, so the ceilings of successive retries never decrease.
Sourcepub fn delays(&self, draws: &[f64]) -> Vec<StdDuration>
pub fn delays(&self, draws: &[f64]) -> Vec<StdDuration>
The delays this policy waits between the attempts of one send, one per retry, given one
random draw in [0, 1) per retry.
Each delay lands between zero and the ceiling of its retry, and the schedule is cut short as
soon as the next delay would spend more than RetryPolicy::max_total_delay. There are
therefore at most RetryPolicy::attempts - 1 delays, and they add up to at most
max_total_delay.
A draw that is missing or is not a finite number is read as 1, which asks for the whole
ceiling: an unusable source of randomness makes the client wait longer, never less.
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 moreimpl Copy for RetryPolicy
Source§impl Debug for RetryPolicy
impl Debug for RetryPolicy
Source§impl Default for RetryPolicy
Available on crate feature producer only.
impl Default for RetryPolicy
producer only.Source§fn default() -> Self
fn default() -> Self
Four attempts spread over at most five seconds.
Three retries absorb the blips a webhook emitter meets in production (a connection reset, a rolling deployment answering 503) without holding the caller’s task for long, and the five-second budget bounds what the worst send costs whatever the individual delays turn out to be.
impl Eq for RetryPolicy
Source§impl PartialEq for RetryPolicy
impl PartialEq for RetryPolicy
impl StructuralPartialEq for RetryPolicy
Auto Trait Implementations§
impl Freeze for RetryPolicy
impl RefUnwindSafe for RetryPolicy
impl Send for RetryPolicy
impl Sync for RetryPolicy
impl Unpin for RetryPolicy
impl UnsafeUnpin for RetryPolicy
impl UnwindSafe for RetryPolicy
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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