pub struct RetryConfig {
pub max_attempts: u32,
pub initial_backoff_ms: u64,
pub max_backoff_ms: u64,
pub multiplier: f64,
pub enable_jitter: bool,
}Expand description
Retry policy configuration
§Examples
Using the default configuration:
use chie_shared::RetryConfig;
let config = RetryConfig::default();
assert_eq!(config.max_attempts, 3);
assert_eq!(config.initial_backoff_ms, 100);
assert_eq!(config.multiplier, 2.0);
assert!(config.enable_jitter);
// Check if retries are exhausted
assert!(!config.is_exhausted(0));
assert!(!config.is_exhausted(2));
assert!(config.is_exhausted(3));Building a custom aggressive retry policy:
use chie_shared::RetryConfigBuilder;
let config = RetryConfigBuilder::new()
.max_attempts(5)
.initial_backoff_ms(100)
.max_backoff_ms(10_000)
.multiplier(2.0)
.enable_jitter(false)
.build();
assert_eq!(config.max_attempts, 5);
assert_eq!(config.initial_backoff_ms, 100);
assert!(!config.enable_jitter);
// Calculate backoff delays (without jitter) - exponential backoff
assert_eq!(config.next_backoff_ms(0), 100); // 100 * 2^0
assert_eq!(config.next_backoff_ms(1), 200); // 100 * 2^1
assert_eq!(config.next_backoff_ms(2), 400); // 100 * 2^2
assert_eq!(config.next_backoff_ms(3), 800); // 100 * 2^3Fields§
§max_attempts: u32Maximum number of retry attempts
initial_backoff_ms: u64Initial backoff delay in milliseconds
max_backoff_ms: u64Maximum backoff delay in milliseconds
multiplier: f64Backoff multiplier (exponential)
enable_jitter: boolEnable jitter to avoid thundering herd
Implementations§
Source§impl RetryConfig
impl RetryConfig
Sourcepub const fn is_exhausted(&self, attempt: u32) -> bool
pub const fn is_exhausted(&self, attempt: u32) -> bool
Check if retries are exhausted
Sourcepub fn next_backoff_ms(&self, attempt: u32) -> u64
pub fn next_backoff_ms(&self, attempt: u32) -> u64
Calculate next backoff delay with jitter
Sourcepub fn validate(&self) -> ChieResult<()>
pub fn validate(&self) -> ChieResult<()>
Trait Implementations§
Source§impl Clone for RetryConfig
impl Clone for RetryConfig
Source§fn clone(&self) -> RetryConfig
fn clone(&self) -> RetryConfig
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for RetryConfig
impl Debug for RetryConfig
Source§impl Default for RetryConfig
impl Default for RetryConfig
Source§impl<'de> Deserialize<'de> for RetryConfig
impl<'de> Deserialize<'de> for RetryConfig
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for RetryConfig
impl RefUnwindSafe for RetryConfig
impl Send for RetryConfig
impl Sync for RetryConfig
impl Unpin for RetryConfig
impl UnwindSafe for RetryConfig
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more