systemprompt_sync/api_client/
retry.rs1use std::time::Duration;
5
6#[derive(Debug, Clone, Copy)]
7pub struct RetryConfig {
8 pub max_attempts: u32,
9 pub initial_delay: Duration,
10 pub max_delay: Duration,
11 pub exponential_base: u32,
12}
13
14impl Default for RetryConfig {
15 fn default() -> Self {
16 Self {
17 max_attempts: 5,
18 initial_delay: Duration::from_secs(2),
19 max_delay: Duration::from_secs(30),
20 exponential_base: 2,
21 }
22 }
23}
24
25impl RetryConfig {
26 pub fn next_delay(&self, current: Duration) -> Duration {
27 current
28 .saturating_mul(self.exponential_base)
29 .min(self.max_delay)
30 }
31}