Expand description
Circuit Breaker
Prevents cascading failures by stopping requests to failing services.
§States
- Closed: Normal operation, requests flow through
- Open: Service failing, requests rejected immediately
- Half-Open: Testing if service recovered
§Usage
use std::time::Duration;
use tokio_prompt_orchestrator::enhanced::CircuitBreaker;
use tokio_prompt_orchestrator::enhanced::circuit_breaker::CircuitBreakerError;
let breaker = CircuitBreaker::new(5, 0.5, Duration::from_secs(60));
match breaker.call(|| async {
// Your operation - replace with a real async call
Ok::<&str, &str>("inference result")
}).await {
Ok(result) => println!("{result}"), // Success
Err(CircuitBreakerError::Open) => {
// Circuit open, fail fast
}
Err(CircuitBreakerError::Failed(e)) => {
eprintln!("Operation failed: {e}");
}
}Structs§
- Circuit
Breaker - A circuit breaker that prevents cascading failures by stopping requests to a failing downstream service.
- Circuit
Breaker Stats - A point-in-time snapshot of
CircuitBreakermetrics.
Enums§
- Circuit
Breaker Error - Circuit breaker errors
- Circuit
Status - Current state of a circuit breaker.