Skip to main content

Module retry_policy

Module retry_policy 

Source
Expand description

§Retry Policy

Configurable retry logic with multiple back-off strategies, jitter modes, and async execution support.

§Example

use tokio_prompt_orchestrator::retry_policy::{
    JitterMode, RetryPolicy, RetryStrategy, retry_async,
};

let policy = RetryPolicy {
    strategy: RetryStrategy::ExponentialBackoff {
        initial_ms: 10,
        multiplier: 2.0,
        max_ms: 1000,
    },
    jitter: JitterMode::Full,
    max_attempts: 3,
    retryable_errors: vec![],
};

let call_count = std::sync::atomic::AtomicU32::new(0);
let result: Result<(), String> = retry_async(&policy, || async {
    let n = call_count.fetch_add(1, std::sync::atomic::Ordering::SeqCst) + 1;
    if n < 3 { Err("transient".to_string()) } else { Ok(()) }
}).await;
assert!(result.is_ok());

Structs§

RetryMetrics
Summary of a completed retry sequence.
RetryPolicy
A complete retry configuration.
RetryState
Mutable state tracked across retry attempts.

Enums§

JitterMode
Jitter strategy to reduce correlated retry storms.
RetryStrategy
The back-off strategy that determines how long to wait between retry attempts.

Functions§

retry_async
Executes f up to policy.max_attempts times, sleeping between attempts according to the policy, and returns the first Ok result or the last error.