pub struct RestartTracker {
pub restart_count: u32,
pub window_start: Instant,
pub last_restart: Option<Instant>,
pub backoff_ms: u64,
}Expand description
Restart state tracking per supervised agent.
Fields§
§restart_count: u32Number of restarts in the current window.
window_start: InstantWhen the current budget window started.
last_restart: Option<Instant>When the last restart occurred.
backoff_ms: u64Current backoff delay in milliseconds (exponential: 100ms -> 30s max).
Implementations§
Source§impl RestartTracker
impl RestartTracker
Sourcepub fn next_backoff_ms(&self) -> u64
pub fn next_backoff_ms(&self) -> u64
Calculate the next backoff delay in milliseconds.
Exponential backoff: 100ms * 2^(restart_count - 1), capped at 30s.
Preserved as the hardcoded fallback. See
Self::next_backoff_ms_with_model for the EML-aware variant
used by the supervisor. The fallback remains reachable so
callers without a model (and every existing test) behave
identically.
Sourcepub fn next_backoff_ms_with_model(
&self,
model: Option<&RestartStrategyModel>,
failure_type: u32,
uptime_secs: f64,
system_load: f64,
) -> u64
pub fn next_backoff_ms_with_model( &self, model: Option<&RestartStrategyModel>, failure_type: u32, uptime_secs: f64, system_load: f64, ) -> u64
Calculate the next backoff delay, consulting an optional
RestartStrategyModel.
When model is None or untrained, this returns the same
exponential-backoff value as Self::next_backoff_ms (the
model’s predict falls back to the identical formula when
!is_trained). When trained, the model’s learned delay is used
instead.
failure_type is the error-kind ordinal (0 = unknown / default
when the caller doesn’t track failure kinds), uptime_secs is
the agent uptime before the failure, and system_load is a
normalised 0.0-1.0 load signal.
NOTE(eml-swap): wired — Finding #5 (RestartStrategyModel).
Sourcepub fn check_window(&mut self, budget: &RestartBudget)
pub fn check_window(&mut self, budget: &RestartBudget)
Check if the restart budget window has expired and reset if so.
Sourcepub fn record_restart(&mut self, budget: &RestartBudget) -> bool
pub fn record_restart(&mut self, budget: &RestartBudget) -> bool
Record a restart attempt. Returns true if within budget,
false if budget exceeded.
Sourcepub fn record_restart_with_model(
&mut self,
budget: &RestartBudget,
model: Option<&RestartStrategyModel>,
failure_type: u32,
uptime_secs: f64,
system_load: f64,
) -> bool
pub fn record_restart_with_model( &mut self, budget: &RestartBudget, model: Option<&RestartStrategyModel>, failure_type: u32, uptime_secs: f64, system_load: f64, ) -> bool
Record a restart attempt with an optional learned
RestartStrategyModel.
Behaviour is identical to Self::record_restart when model
is None or untrained; when trained, the computed
backoff_ms is sourced from the model.
NOTE(eml-swap): wired — Finding #5 (RestartStrategyModel).
Sourcepub fn is_exhausted(&self, budget: &RestartBudget) -> bool
pub fn is_exhausted(&self, budget: &RestartBudget) -> bool
Check whether the restart budget is exhausted.
Sourcepub fn remaining(&self, budget: &RestartBudget) -> u32
pub fn remaining(&self, budget: &RestartBudget) -> u32
Number of restarts remaining in the current window.
Returns 0 if the budget is already exhausted. Returns
max_restarts if the window has expired (it would reset
on the next record_restart).
Sourcepub fn should_restart(strategy: &RestartStrategy, exit_code: i32) -> bool
pub fn should_restart(strategy: &RestartStrategy, exit_code: i32) -> bool
Determine whether a process should be restarted based on the strategy and exit code.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for RestartTracker
impl RefUnwindSafe for RestartTracker
impl Send for RestartTracker
impl Sync for RestartTracker
impl Unpin for RestartTracker
impl UnsafeUnpin for RestartTracker
impl UnwindSafe for RestartTracker
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more