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: 3initial_delay: 5 secondsmax_delay: 60 secondsmultiplier: 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: u32Maximum number of attempts (including the initial attempt).
A value of 1 means no retries; only the initial attempt is made.
initial_delay: DurationDelay before the first retry.
Subsequent delays are computed by multiplying by multiplier.
max_delay: DurationMaximum delay between retries.
The computed delay is capped at this value to prevent excessively long waits.
multiplier: f64Multiplier applied to the delay after each retry.
A value of 2.0 doubles the delay each time.
Implementations§
Source§impl RetryPolicy
impl RetryPolicy
Sourcepub const DEFAULT_MAX_ATTEMPTS: u32 = 3
pub const DEFAULT_MAX_ATTEMPTS: u32 = 3
Default maximum attempts.
Sourcepub const DEFAULT_INITIAL_DELAY: Duration
pub const DEFAULT_INITIAL_DELAY: Duration
Default initial delay (5 seconds).
Sourcepub const DEFAULT_MAX_DELAY: Duration
pub const DEFAULT_MAX_DELAY: Duration
Default maximum delay (60 seconds).
Sourcepub const DEFAULT_MULTIPLIER: f64 = 2.0
pub const DEFAULT_MULTIPLIER: f64 = 2.0
Default multiplier (2.0).
Sourcepub const MIN_MAX_ATTEMPTS: u32 = 1
pub const MIN_MAX_ATTEMPTS: u32 = 1
Minimum value for max_attempts.
Sourcepub const fn with_max_attempts(self, max_attempts: u32) -> Self
pub const fn with_max_attempts(self, max_attempts: u32) -> Self
Sourcepub const fn with_initial_delay(self, delay: Duration) -> Self
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.
Sourcepub const fn with_max_delay(self, delay: Duration) -> Self
pub const fn with_max_delay(self, delay: Duration) -> Self
Sets the maximum delay between retries.
Sourcepub fn with_multiplier(self, multiplier: f64) -> Self
pub fn with_multiplier(self, multiplier: f64) -> Self
Sourcepub fn delay_for_retry(&self, retry: u32) -> Duration
pub fn delay_for_retry(&self, retry: u32) -> Duration
Trait Implementations§
Source§impl Clone for RetryPolicy
impl Clone for RetryPolicy
Source§fn clone(&self) -> RetryPolicy
fn clone(&self) -> RetryPolicy
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more