RetryConfig

Struct RetryConfig 

Source
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^3

Fields§

§max_attempts: u32

Maximum number of retry attempts

§initial_backoff_ms: u64

Initial backoff delay in milliseconds

§max_backoff_ms: u64

Maximum backoff delay in milliseconds

§multiplier: f64

Backoff multiplier (exponential)

§enable_jitter: bool

Enable jitter to avoid thundering herd

Implementations§

Source§

impl RetryConfig

Source

pub const fn is_exhausted(&self, attempt: u32) -> bool

Check if retries are exhausted

Source

pub fn next_backoff_ms(&self, attempt: u32) -> u64

Calculate next backoff delay with jitter

Source

pub fn validate(&self) -> ChieResult<()>

Validate the retry configuration

§Errors

Returns error if configuration is invalid

Trait Implementations§

Source§

impl Clone for RetryConfig

Source§

fn clone(&self) -> RetryConfig

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for RetryConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for RetryConfig

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for RetryConfig

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for RetryConfig

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,