use super::config::RetryConfig;
use super::delay_strategy::RetryDelayStrategy;
use std::time::Duration;
#[derive(Debug, Clone)]
pub struct SimpleRetryConfig {
max_attempts: u32,
delay_strategy: RetryDelayStrategy,
jitter_factor: f64,
max_duration: Option<Duration>,
operation_timeout: Option<Duration>,
}
impl SimpleRetryConfig {
pub fn new() -> Self {
Self {
max_attempts: Self::DEFAULT_MAX_ATTEMPTS,
delay_strategy: Self::DEFAULT_DELAY_STRATEGY,
jitter_factor: Self::DEFAULT_JITTER_FACTOR,
max_duration: None,
operation_timeout: None,
}
}
pub fn with_params(
max_attempts: u32,
delay_strategy: RetryDelayStrategy,
jitter_factor: f64,
max_duration: Option<Duration>,
operation_timeout: Option<Duration>,
) -> Self {
Self {
max_attempts,
delay_strategy,
jitter_factor,
max_duration,
operation_timeout,
}
}
}
impl Default for SimpleRetryConfig {
fn default() -> Self {
Self::new()
}
}
impl RetryConfig for SimpleRetryConfig {
fn max_attempts(&self) -> u32 {
self.max_attempts
}
fn set_max_attempts(&mut self, max_attempts: u32) -> &mut Self {
self.max_attempts = max_attempts;
self
}
fn max_duration(&self) -> Option<Duration> {
self.max_duration
}
fn set_max_duration(&mut self, max_duration: Option<Duration>) -> &mut Self {
self.max_duration = max_duration;
self
}
fn operation_timeout(&self) -> Option<Duration> {
self.operation_timeout
}
fn set_operation_timeout(&mut self, timeout: Option<Duration>) -> &mut Self {
self.operation_timeout = timeout;
self
}
fn delay_strategy(&self) -> RetryDelayStrategy {
self.delay_strategy.clone()
}
fn set_delay_strategy(&mut self, delay_strategy: RetryDelayStrategy) -> &mut Self {
self.delay_strategy = delay_strategy;
self
}
fn jitter_factor(&self) -> f64 {
self.jitter_factor
}
fn set_jitter_factor(&mut self, jitter_factor: f64) -> &mut Self {
self.jitter_factor = jitter_factor;
self
}
}