azure_core/policies/retry_policies/
fixed_retry.rs1use std::time::Duration;
2
3#[derive(Debug, Clone, PartialEq, Eq)]
10pub struct FixedRetryPolicy {
11    delay: Duration,
12    max_retries: u32,
13    max_elapsed: Duration,
14}
15
16impl FixedRetryPolicy {
17    pub(crate) fn new(delay: Duration, max_retries: u32, max_elapsed: Duration) -> Self {
18        Self {
19            delay: delay.max(Duration::from_millis(10)),
20            max_retries,
21            max_elapsed,
22        }
23    }
24}
25
26impl super::RetryPolicy for FixedRetryPolicy {
27    fn is_expired(&self, time_since_start: Duration, retry_count: u32) -> bool {
28        retry_count >= self.max_retries || time_since_start >= self.max_elapsed
29    }
30
31    fn sleep_duration(&self, _retry_count: u32) -> Duration {
32        let sleep_ms = self.delay.as_millis() as u64 + u64::from(rand::random::<u8>());
33        Duration::from_millis(sleep_ms)
34    }
35}