RetryPolicy

Struct RetryPolicy 

Source
pub struct RetryPolicy {
    pub max_attempts: u32,
    pub initial_delay: Duration,
    pub max_delay: Duration,
    pub multiplier: f64,
}
Expand description

Configuration for exponential backoff retry behavior.

Controls how many times to retry a failed operation and how long to wait between attempts. Uses exponential backoff with a configurable multiplier and maximum delay cap.

§Defaults

  • max_attempts: 3
  • initial_delay: 5 seconds
  • max_delay: 60 seconds
  • multiplier: 2.0

§Example

use ddns_a::webhook::RetryPolicy;
use std::time::Duration;

// Create with defaults
let policy = RetryPolicy::default();

// Or customize via builder
let custom = RetryPolicy::new()
    .with_max_attempts(5)
    .with_initial_delay(Duration::from_secs(1))
    .with_max_delay(Duration::from_secs(30))
    .with_multiplier(1.5);

Fields§

§max_attempts: u32

Maximum number of attempts (including the initial attempt).

A value of 1 means no retries; only the initial attempt is made.

§initial_delay: Duration

Delay before the first retry.

Subsequent delays are computed by multiplying by multiplier.

§max_delay: Duration

Maximum delay between retries.

The computed delay is capped at this value to prevent excessively long waits.

§multiplier: f64

Multiplier applied to the delay after each retry.

A value of 2.0 doubles the delay each time.

Implementations§

Source§

impl RetryPolicy

Source

pub const DEFAULT_MAX_ATTEMPTS: u32 = 3

Default maximum attempts.

Source

pub const DEFAULT_INITIAL_DELAY: Duration

Default initial delay (5 seconds).

Source

pub const DEFAULT_MAX_DELAY: Duration

Default maximum delay (60 seconds).

Source

pub const DEFAULT_MULTIPLIER: f64 = 2.0

Default multiplier (2.0).

Source

pub const MIN_MAX_ATTEMPTS: u32 = 1

Minimum value for max_attempts.

Source

pub const fn new() -> Self

Creates a new retry policy with default values.

Source

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

Sets the maximum number of attempts.

§Panics

Panics if max_attempts is less than 1.

Source

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

Sets the initial delay between retries.

Zero delay is supported (useful for testing with InstantSleeper) but not recommended for production as it creates a tight retry loop.

Source

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

Sets the maximum delay between retries.

Source

pub fn with_multiplier(self, multiplier: f64) -> Self

Sets the delay multiplier.

§Panics

Panics if multiplier is not positive (must be > 0.0).

Source

pub fn delay_for_retry(&self, retry: u32) -> Duration

Computes the delay for a given retry number (0-indexed).

§Arguments
  • retry - The retry number (0 = delay before first retry, 1 = delay before second retry, etc.)
§Returns

The delay to wait before this retry, capped at max_delay.

Source

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

Returns true if the given attempt number should be retried.

§Arguments
  • attempt - The attempt number (1 = first attempt, 2 = first retry, etc.)
§Returns

true if the attempt is within the allowed number of attempts.

Trait Implementations§

Source§

impl Clone for RetryPolicy

Source§

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

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.
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: 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: 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 = 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.
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