Skip to main content

RetryPolicy

Struct RetryPolicy 

Source
pub struct RetryPolicy { /* private fields */ }
Expand description

When a Client tries a GET call again.

Retries are off unless a policy is set with Client::retry. With one, a GET call (health, faces, and request with "GET") is tried again after a connection failure or timeout (Error::Transport), or an HTTP 429 or 503 answer, up to max_attempts attempts in all. A POST is never retried: repeating validate, generate, check or project_face could submit a payment file twice.

The wait before retry n (from 1) is exponential with jitter: a random point in the upper half of min(max_delay, base_delay * 2^(n-1)). A Retry-After header on a 429 or 503, in seconds or as an HTTP date, is waited exactly instead; one asking for longer than max_delay ends the retries and returns that answer, so the client never comes back earlier than the server asked. The client’s timeout applies to each attempt.

use pain001_sdk::{Client, RetryPolicy};
use std::time::Duration;

let policy = RetryPolicy::new()
    .with_max_attempts(4)
    .with_base_delay(Duration::from_millis(100));
let client = Client::new("http://127.0.0.1:8000").retry(policy);
assert_eq!(policy.max_delay(), RetryPolicy::DEFAULT_MAX_DELAY);

Implementations§

Source§

impl RetryPolicy

Source

pub const DEFAULT_MAX_ATTEMPTS: u32 = 3

Attempts in all, the first one included, of RetryPolicy::new.

Source

pub const DEFAULT_BASE_DELAY: Duration

The wait before the first retry, before jitter.

Source

pub const DEFAULT_MAX_DELAY: Duration

The longest wait before any retry, and the longest Retry-After honoured.

Source

pub fn new() -> Self

The defaults: 3 attempts, 200 ms base delay, 5 s maximum delay.

Source

pub fn with_max_attempts(self, attempts: u32) -> Self

Sets the number of attempts in all, the first one included. 1 (or 0, read as 1) makes the policy retry nothing.

Source

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

Sets the wait before the first retry, before jitter; each later wait doubles it, up to the maximum delay.

Source

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

Sets the longest wait before any retry, which is also the longest Retry-After the client waits for.

Source

pub fn max_attempts(&self) -> u32

Attempts in all, the first one included.

Source

pub fn base_delay(&self) -> Duration

The wait before the first retry, before jitter.

Source

pub fn max_delay(&self) -> Duration

The longest wait before any retry.

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

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.