File size: 1,501 Bytes
1851bae
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
use derive_setters::Setters;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

/// Configuration for retry mechanism.
#[derive(
    Default, Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema, fake::Dummy, Setters,
)]
#[serde(rename_all = "snake_case")]
#[setters(into)]
pub struct RetryConfig {
    /// Initial backoff delay in milliseconds for retry operations
    pub initial_backoff_ms: u64,
    /// Minimum delay in milliseconds between retry attempts
    pub min_delay_ms: u64,
    /// Backoff multiplication factor for each retry attempt
    pub backoff_factor: u64,
    /// Maximum number of retry attempts
    pub max_attempts: usize,
    /// HTTP status codes that should trigger retries
    pub status_codes: Vec<u16>,
    /// Maximum delay between retries in seconds
    pub max_delay_secs: Option<u64>,
    /// Whether to suppress retry error logging and events
    pub suppress_errors: bool,
}

#[cfg(test)]
mod tests {
    use pretty_assertions::assert_eq;

    use super::*;

    #[test]
    fn test_retry_config_fields() {
        let config = RetryConfig {
            initial_backoff_ms: 200,
            min_delay_ms: 1000,
            backoff_factor: 2,
            max_attempts: 8,
            status_codes: vec![429, 500, 502, 503, 504, 408, 522, 524, 520, 529],
            max_delay_secs: None,
            suppress_errors: false,
        };
        assert_eq!(config.initial_backoff_ms, 200);
        assert_eq!(config.suppress_errors, false);
    }
}