Skip to main content

Crate do_over

Crate do_over 

Source
Expand description

§do-over

An async-first resilience and transient fault handling library for Rust, inspired by the .NET Polly library.

§Overview

do-over provides a set of resilience policies that can be used to make your applications more robust when dealing with transient failures, network issues, and other common problems in distributed systems.

§Policies

§Utilities

§Quick Start

use do_over::{policy::Policy, retry::RetryPolicy, timeout::TimeoutPolicy, wrap::Wrap, error::DoOverError};
use std::time::Duration;

// Create a policy that retries 3 times with a 5s timeout per attempt
let policy = Wrap::new(
    RetryPolicy::fixed(3, Duration::from_millis(100)),
    TimeoutPolicy::new(Duration::from_secs(5)),
);

// Execute your operation with resilience
let result: Result<&str, DoOverError<&str>> = policy.execute(|| async {
    Ok("success")
}).await;

§Policy Composition

Policies can be composed using wrap::Wrap. The recommended ordering (from outer to inner) is:

  1. Bulkhead - Limit concurrency first
  2. Circuit Breaker - Fast-fail if too many errors
  3. Rate Limiter - Throttle requests
  4. Retry - Handle transient failures
  5. Timeout - Bound individual attempts

§Feature Flags

  • http - Enables reqwest integration
  • metrics-prometheus - Prometheus metrics
  • metrics-otel - OpenTelemetry metrics

Modules§

bulkhead
Bulkhead policy for concurrency limiting.
cache
Cache policy for caching successful results.
circuit_breaker
Circuit breaker policy for preventing cascading failures.
context
Policy context for passing metadata through execution.
error
Error types for do_over policies.
fallback
Fallback policy for providing default values on failure.
hedge
Hedge policy for reducing tail latency.
metrics
policy
Core policy trait for resilience patterns.
rate_limit
Rate limiter policy using a token bucket algorithm.
retry
Retry policy for handling transient failures.
timeout
Timeout policy for time-bounded operations.
tower
wrap
Policy composition using the Wrap combinator.