pub struct BackoffState { /* private fields */ }Expand description
Mutable state tracker for an individual service’s backoff history.
One BackoffState instance is maintained per supervised service inside
the JanusSupervisor.
Implementations§
Source§impl BackoffState
impl BackoffState
Sourcepub fn new(config: BackoffConfig) -> Self
pub fn new(config: BackoffConfig) -> Self
Create a fresh backoff state with the given configuration.
Sourcepub fn with_defaults() -> Self
pub fn with_defaults() -> Self
Create with default configuration.
Sourcepub fn record_start(&mut self)
pub fn record_start(&mut self)
Record that the service has started (or restarted) successfully.
Called by the supervisor when a service’s run() method is entered.
Sourcepub fn maybe_reset_on_cooldown(&mut self)
pub fn maybe_reset_on_cooldown(&mut self)
Check if the cooldown period has elapsed since the last start, and if so, reset the attempt counter.
Called by the supervisor when a service exits so that a service which ran healthily for a long time doesn’t carry old failure history into its next restart.
Sourcepub fn next_backoff(&mut self) -> BackoffAction
pub fn next_backoff(&mut self) -> BackoffAction
Record a failure and compute the next action.
Returns BackoffAction::Retry with the jittered delay, or
BackoffAction::CircuitOpen if the circuit breaker has tripped.
Sourcepub fn recent_failures(&self) -> usize
pub fn recent_failures(&self) -> usize
Number of failures recorded within the circuit-breaker window.
Trait Implementations§
Source§impl Clone for BackoffState
impl Clone for BackoffState
Source§fn clone(&self) -> BackoffState
fn clone(&self) -> BackoffState
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more