openapp_sdk_core/retry.rs
1//! Retry policy configuration.
2//!
3//! The default policy mirrors the behaviour of most modern `SaaS` SDKs: exponential
4//! backoff on 408 / 425 / 429 / 5xx responses and transport errors, honouring the
5//! `Retry-After` header when present.
6
7use std::time::Duration;
8
9/// Retry policy applied by the core transport layer.
10#[derive(Debug, Clone)]
11pub struct RetryPolicy {
12 /// Maximum number of retry attempts after the initial request. `0` disables retries.
13 pub max_retries: u32,
14 /// Initial backoff between the first and second attempt.
15 pub initial_backoff: Duration,
16 /// Backoff multiplier between attempts.
17 pub backoff_multiplier: f64,
18 /// Cap on a single backoff interval.
19 pub max_backoff: Duration,
20 /// Upper bound on total time spent retrying a single logical request.
21 pub total_deadline: Duration,
22}
23
24impl Default for RetryPolicy {
25 fn default() -> Self {
26 Self {
27 max_retries: 3,
28 initial_backoff: Duration::from_millis(250),
29 backoff_multiplier: 2.0,
30 max_backoff: Duration::from_secs(8),
31 total_deadline: Duration::from_secs(30),
32 }
33 }
34}
35
36impl RetryPolicy {
37 /// Policy that disables all retries. Used primarily for determinism in tests.
38 #[must_use]
39 pub fn none() -> Self {
40 Self {
41 max_retries: 0,
42 ..Self::default()
43 }
44 }
45}