Skip to main content

Module retry

Module retry 

Source
Available on crate feature graph only.
Expand description

Per-node retry with exponential backoff.

A node that fails aborts the run. That is right for a logic error and wrong for a call to a service that is briefly unavailable, so a policy can be attached per node to try again with a growing delay.

Retry is off unless configured: a node with no policy runs once. A policy from RetryPolicy::default allows ten attempts, so a graph that sets no policy behaves exactly as before.

§Example

use adk_graph::retry::{RetryOn, RetryPolicy};
use std::time::Duration;

let policy = RetryPolicy::new(4)
    .with_initial_delay(Duration::from_millis(200))
    .with_max_delay(Duration::from_secs(5))
    .with_backoff_factor(2.0)
    .with_jitter(0.0)
    .with_retry_on(RetryOn::Any);

// Attempt 1 fails, then 200ms, 400ms, 800ms.
assert_eq!(policy.delay_for_attempt(1), Duration::from_millis(200));
assert_eq!(policy.delay_for_attempt(2), Duration::from_millis(400));
assert_eq!(policy.delay_for_attempt(3), Duration::from_millis(800));

Structs§

RetryPolicy
How many times a node is attempted, and how long between attempts.

Enums§

RetryOn
Which failures a policy retries.