Skip to main content

CommonLibrary/Transport/
Retry.rs

1#![allow(non_snake_case, non_camel_case_types, non_upper_case_globals)]
2//! # Retry Strategies
3//!
4//! Retry configuration and strategies for transport operations.
5
6use std::time::Duration;
7
8/// Configuration for retry behaviour.
9#[derive(Debug, Clone)]
10pub struct RetryConfiguration {
11	/// Maximum number of retry attempts.
12	pub MaximumAttempts:u32,
13
14	/// Base delay for exponential backoff.
15	pub BaseDelay:Duration,
16
17	/// Maximum delay cap.
18	pub MaximumDelay:Duration,
19
20	/// Whether to add jitter to retry delays.
21	pub JitterEnabled:bool,
22}
23
24impl Default for RetryConfiguration {
25	fn default() -> Self {
26		Self {
27			MaximumAttempts:3,
28
29			BaseDelay:Duration::from_millis(100),
30
31			MaximumDelay:Duration::from_secs(10),
32
33			JitterEnabled:true,
34		}
35	}
36}
37
38/// Retry strategy selector.
39#[derive(Debug, Clone, Copy, PartialEq, Eq)]
40pub enum RetryStrategy {
41	/// No retries.
42	None,
43
44	/// Fixed delay between retries.
45	Fixed,
46
47	/// Exponential backoff.
48	Exponential,
49
50	/// Exponential backoff with jitter.
51	ExponentialJitter,
52}