pub struct CircuitBreakerState { /* private fields */ }Expand description
Runtime state of a circuit breaker
Tracks the current state (Closed/Open/HalfOpen) and failure count for a single node’s circuit breaker.
Implementations§
Source§impl CircuitBreakerState
impl CircuitBreakerState
Sourcepub fn should_allow(&mut self, config: &CircuitBreakerConfig) -> bool
pub fn should_allow(&mut self, config: &CircuitBreakerConfig) -> bool
Check if the circuit allows execution
Returns true if the node should be allowed to execute.
Returns false if the circuit is open and the cooldown has not elapsed.
This method does NOT consume half-open probe budget. Call
mark_half_open_attempt after the
task actually executes to consume the probe budget.
Sourcepub fn mark_half_open_attempt(&mut self)
pub fn mark_half_open_attempt(&mut self)
Consume a half-open probe attempt after actual execution
Call this after a task actually executes (success or failure) in
HalfOpen state to consume the probe budget. This ensures the budget
is consumed by executions, not eligibility checks.
Sourcepub fn record_success(&mut self)
pub fn record_success(&mut self)
Record a successful execution
Resets the circuit to Closed state. If the circuit is currently Open, this is a no-op (success cannot be recorded for an Open circuit because no execution is allowed).
Sourcepub fn record_failure(&mut self, config: &CircuitBreakerConfig)
pub fn record_failure(&mut self, config: &CircuitBreakerConfig)
Record a failed execution
Sourcepub const fn state(&self) -> &CircuitState
pub const fn state(&self) -> &CircuitState
Get the current circuit state
Sourcepub const fn consecutive_failures(&self) -> usize
pub const fn consecutive_failures(&self) -> usize
Get the number of consecutive failures
Trait Implementations§
Source§impl Clone for CircuitBreakerState
impl Clone for CircuitBreakerState
Source§fn clone(&self) -> CircuitBreakerState
fn clone(&self) -> CircuitBreakerState
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more