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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//! Retry policy for transient HTTP errors with exponential backoff.
use Duration;
/// Configuration for retrying transient errors with exponential backoff.
///
/// When attached to an [`NifiClient`](crate::NifiClient) via
/// [`NifiClientBuilder::retry_policy`](crate::NifiClientBuilder::retry_policy),
/// HTTP helpers will automatically retry requests that fail with
/// [retryable](crate::NifiError::is_retryable) errors.
///
/// # Example
///
/// ```
/// use std::time::Duration;
/// use nifi_rust_client::config::retry::RetryPolicy;
///
/// let policy = RetryPolicy::default();
/// assert_eq!(policy.max_retries, 3);
///
/// // Exponential backoff: 500ms, 1000ms, 2000ms, …
/// assert_eq!(policy.backoff_for(0), Duration::from_millis(500));
/// assert_eq!(policy.backoff_for(1), Duration::from_millis(1000));
/// assert_eq!(policy.backoff_for(2), Duration::from_millis(2000));
///
/// // Capped at max_backoff
/// let policy = RetryPolicy {
/// max_retries: 10,
/// initial_backoff: Duration::from_secs(1),
/// max_backoff: Duration::from_secs(5),
/// };
/// assert_eq!(policy.backoff_for(5), Duration::from_secs(5));
/// ```