retry
ModuleContents
use utopia_client::Backoff;pub struct BackoffThe default, best-practice strategy: retry only idempotent methods
(GET, HEAD, PUT, DELETE, OPTIONS, TRACE), only on network
failures (Error::is_network) and overloaded responses (429, 502, 503,
504), with exponential backoff and full jitter. A numeric Retry-After
is honoured, capped to the maximum delay.
use utopia_client::{Backoff, Error, Outcome, Request, Strategy};
// A randomizer that always returns 1.0 shows the ceiling of each delay.
let backoff = Backoff::new(4, 0.1, 10.0, 2.0).with_randomizer(|| 1.0);
let request = Request::new("GET", "https://example.com/")?;
let error = Error::Connection("reset".into());
assert_eq!(backoff.delay(&request, 1, Outcome::Error(&error)), Some(0.1));
assert_eq!(backoff.delay(&request, 2, Outcome::Error(&error)), Some(0.2));
assert_eq!(backoff.delay(&request, 4, Outcome::Error(&error)), None);Debug, Default.use utopia_client::Retry;pub struct Retry<A, S = Backoff, W = Timer>An adapter that retries another according to a Strategy. The
strategy owns every decision (which outcomes to retry, how long to wait,
when to stop); the decorator only loops and sleeps. A stream is retried
only while no byte has reached its sink: replaying would duplicate them.
use utopia_client::{Backoff, Client, Http, Request, Retry};
let client = Client::new(Retry::new(Http::new(), Backoff::default()));
let response = client.send(Request::new("GET", "https://example.com/")?).await?;use utopia_client::Timer;pub struct TimerSleeps on tokio's timer.
use utopia_client::Outcome;pub enum Outcome<'a>What happened on one attempt: the response, or the error.
use utopia_client::Sleep;pub trait Sleep: Send + SyncWaits between attempts. The default sleeps on tokio's timer; give your own to record or skip waits.
use utopia_client::Strategy;pub trait Strategy: Send + SyncDecides whether to retry after an attempt. Implement it for a policy of your own.