Skip to main content

RestartTracker

Struct RestartTracker 

Source
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: u32

Number of restarts in the current window.

§window_start: Instant

When the current budget window started.

§last_restart: Option<Instant>

When the last restart occurred.

§backoff_ms: u64

Current backoff delay in milliseconds (exponential: 100ms -> 30s max).

Implementations§

Source§

impl RestartTracker

Source

pub fn new() -> Self

Create a new tracker with the window starting now.

Source

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.

Source

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).

Source

pub fn check_window(&mut self, budget: &RestartBudget)

Check if the restart budget window has expired and reset if so.

Source

pub fn record_restart(&mut self, budget: &RestartBudget) -> bool

Record a restart attempt. Returns true if within budget, false if budget exceeded.

Source

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).

Source

pub fn is_exhausted(&self, budget: &RestartBudget) -> bool

Check whether the restart budget is exhausted.

Source

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).

Source

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§

Source§

impl Default for RestartTracker

Available on crate feature os-patterns only.
Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Pointee for T

Source§

type Pointer = u32

Source§

fn debug( pointer: <T as Pointee>::Pointer, f: &mut Formatter<'_>, ) -> Result<(), Error>

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more