retry_policies/retry_policy.rs
1use std::time::SystemTime;
2
3/// A policy for deciding whether and when to retry.
4pub trait RetryPolicy {
5 /// Determine if a task should be retried according to a retry policy.
6 fn should_retry(&self, request_start_time: SystemTime, n_past_retries: u32) -> RetryDecision;
7}
8
9/// Outcome of evaluating a retry policy for a failed task.
10#[derive(Debug)]
11pub enum RetryDecision {
12 /// Retry after the specified timestamp.
13 Retry { execute_after: SystemTime },
14 /// Give up.
15 DoNotRetry,
16}
17
18/// How to apply jitter to the retry intervals.
19#[derive(Debug, Clone, Copy, PartialEq, Eq)]
20#[non_exhaustive]
21pub enum Jitter {
22 /// Don't apply any jitter.
23 None,
24 /// Jitter between 0 and the calculated backoff duration.
25 Full,
26 /// Jitter between `min_retry_interval` and the calculated backoff duration.
27 Bounded,
28}