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	/// Base delay for exponential backoff.
14	pub BaseDelay:Duration,
15	/// Maximum delay cap.
16	pub MaximumDelay:Duration,
17	/// Whether to add jitter to retry delays.
18	pub JitterEnabled:bool,
19}
20
21impl Default for RetryConfiguration {
22	fn default() -> Self {
23		Self {
24			MaximumAttempts:3,
25			BaseDelay:Duration::from_millis(100),
26			MaximumDelay:Duration::from_secs(10),
27			JitterEnabled:true,
28		}
29	}
30}
31
32/// Retry strategy selector.
33#[derive(Debug, Clone, Copy, PartialEq, Eq)]
34pub enum RetryStrategy {
35	/// No retries.
36	None,
37	/// Fixed delay between retries.
38	Fixed,
39	/// Exponential backoff.
40	Exponential,
41	/// Exponential backoff with jitter.
42	ExponentialJitter,
43}