Skip to main content

CircuitBreakerBackend

Trait CircuitBreakerBackend 

Source
pub trait CircuitBreakerBackend: Send + Sync {
    // Required methods
    fn increment_failures(&self, service: &str) -> u32;
    fn reset_failures(&self, service: &str);
    fn get_failures(&self, service: &str) -> u32;
    fn set_open_at(&self, service: &str, at: Instant);
    fn clear_open_at(&self, service: &str);
    fn get_open_at(&self, service: &str) -> Option<Instant>;
}
Expand description

Backend for circuit breaker state storage.

Implement this trait to share circuit breaker state across processes (e.g., via Redis). The in-process default is InMemoryCircuitBreakerBackend.

Note: Methods are synchronous to avoid pulling in async-trait. A distributed backend (e.g., Redis) can internally spawn a Tokio runtime.

Required Methods§

Source

fn increment_failures(&self, service: &str) -> u32

Increment the consecutive failure count for service and return the new count.

Source

fn reset_failures(&self, service: &str)

Reset the consecutive failure count for service to zero.

Source

fn get_failures(&self, service: &str) -> u32

Return the current consecutive failure count for service.

Source

fn set_open_at(&self, service: &str, at: Instant)

Record the instant at which the circuit was opened for service.

Source

fn clear_open_at(&self, service: &str)

Clear the open-at timestamp, effectively moving the circuit to Closed or HalfOpen.

Source

fn get_open_at(&self, service: &str) -> Option<Instant>

Return the instant at which the circuit was opened, or None if it is not open.

Implementors§