Skip to main content

RetryPolicy

Struct RetryPolicy 

Source
pub struct RetryPolicy {
    pub max_retries: u32,
    pub backoff_initial: Duration,
    pub backoff_max: Duration,
    pub backoff_jitter: f64,
    pub http_statuses: StatusSet,
    pub respect_retry_after: bool,
    pub max_retry_after: Duration,
    pub retry_connection_errors: bool,
    pub retry_timeouts: bool,
    pub connect_only_before_send: bool,
}
Expand description

Retry policy matching the official TypeSafe SDKs.

Default: 2 retries, 500 ms initial backoff, 5 s cap, 25% jitter, HTTP 408/429/5xx, connection errors, timeouts, and retry-after-ms / Retry-After up to 60 s.

Struct-update from RetryPolicy::default so private fields stay initialized: RetryPolicy { max_retries: 0, ..RetryPolicy::default() }.

§Examples

use typesafe_rs::RetryPolicy;

let none = RetryPolicy::none();
assert_eq!(none.max_retries, 0);

let conservative = RetryPolicy::conservative();
assert!(!conservative.retry_timeouts);

Fields§

§max_retries: u32

Maximum retries after the initial attempt. Default: 2.

§backoff_initial: Duration

First backoff delay. Default: 500 ms.

§backoff_max: Duration

Backoff cap. Default: 5 s.

§backoff_jitter: f64

Fraction of each backoff randomly subtracted, in [0, 1]. Default: 0.25.

§http_statuses: StatusSet

HTTP statuses that are retried. Default: 408, 429, 500–599.

§respect_retry_after: bool

Honor retry-after-ms / Retry-After up to Self::max_retry_after.

§max_retry_after: Duration

Maximum server-requested delay that will be honored. Default: 60 s.

§retry_connection_errors: bool

Retry connection failures. Default: true.

§retry_timeouts: bool

Retry timeouts. Default: true.

§connect_only_before_send: bool

When true, only connection errors that happen before bytes are sent are retried.

Set by RetryPolicy::conservative. Keep the default (false) unless you want that behaviour; prefer ..RetryPolicy::default() in struct updates.

Implementations§

Source§

impl RetryPolicy

Source

pub fn none() -> Self

No retries (max_retries = 0).

Source

pub fn conservative() -> Self

Retry 408/429 and pre-send connection errors only. No 5xx, no timeouts.

Source

pub fn parse_retry_after(headers: &HeaderMap) -> Option<Duration>

Parse retry-after-ms (preferred) or Retry-After into a delay.

Invalid values are ignored (None).

Source

pub fn parse_retry_after_at( headers: &HeaderMap, now: SystemTime, ) -> Option<Duration>

Self::parse_retry_after with an injected now for HTTP-date values.

Source

pub fn delay_after_failure( &self, attempt: u32, headers: Option<&HeaderMap>, ) -> Duration

Delay before the next attempt after a zero-based failed attempt.

Source

pub fn delay_after_failure_with<F>( &self, attempt: u32, headers: Option<&HeaderMap>, rng: F, ) -> Duration
where F: FnOnce() -> f64,

Self::delay_after_failure with an injected RNG in [0, 1).

Tests should call this instead of reimplementing backoff math.

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

Source§

fn default() -> Self

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

impl PartialEq for RetryPolicy

Source§

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

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

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

Inequality operator !=. 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> 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> 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> 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<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