pub struct NetworkRetryPolicy {
pub enabled: bool,
pub max_attempts: u32,
pub initial_delay: Duration,
pub multiplier: f64,
pub max_delay: Duration,
pub jitter_factor: f64,
pub max_attempts_absolute: Option<u32>,
}Expand description
Reconnection and backoff policy for networked components.
Used in component config structs as a reconnect field:
[default.components.redis.reconnect]
max_attempts = 10
initial_delay_ms = 100
max_delay_ms = 30000Fields§
§enabled: boolWhether reconnection is enabled at all.
max_attempts: u32Maximum number of attempts before giving up. 0 means unlimited.
initial_delay: DurationBase delay for the first retry.
multiplier: f64Exponential backoff multiplier applied to each successive attempt.
max_delay: DurationMaximum delay cap regardless of computed backoff.
jitter_factor: f64Jitter factor in [0.0, 1.0]. Actual delay is base ± (base * jitter_factor / 2).
max_attempts_absolute: Option<u32>Hard cap on total retry attempts regardless of max_attempts.
When Some(n), the policy stops retrying after n total attempts
(including the initial call) even if max_attempts is 0 (unlimited).
None (the default) preserves the max_attempts semantics unchanged.
Implementations§
Source§impl NetworkRetryPolicy
impl NetworkRetryPolicy
Sourcepub fn delay_for(&self, attempt: u32) -> Duration
pub fn delay_for(&self, attempt: u32) -> Duration
Computes the sleep duration for a given zero-based attempt number.
Formula: clamp(initial * multiplier^attempt, 0, max_delay) with random jitter.
Sourcepub fn should_retry(&self, attempt: u32) -> bool
pub fn should_retry(&self, attempt: u32) -> bool
Returns true if another retry should be attempted.
attempt is zero-based: 0 = first attempt, 1 = first retry, etc.
When max_attempts_absolute is Some(n), the policy stops after n
total attempts regardless of max_attempts. When None (the default),
only max_attempts governs the limit (where 0 means unlimited).
Trait Implementations§
Source§impl Clone for NetworkRetryPolicy
impl Clone for NetworkRetryPolicy
Source§fn clone(&self) -> NetworkRetryPolicy
fn clone(&self) -> NetworkRetryPolicy
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more