pub struct ServiceLifecycle { /* private fields */ }Expand description
Full lifecycle tracker for a single supervised service.
Wraps the ServicePhase enum with timing data, counters, and
transition validation logic. The supervisor holds one of these per
managed service.
Implementations§
Source§impl ServiceLifecycle
impl ServiceLifecycle
Sourcepub fn new(service_name: impl Into<String>) -> Self
pub fn new(service_name: impl Into<String>) -> Self
Create a new lifecycle tracker in the Starting phase.
Sourcepub fn phase(&self) -> ServicePhase
pub fn phase(&self) -> ServicePhase
Current lifecycle phase.
Sourcepub fn service_name(&self) -> &str
pub fn service_name(&self) -> &str
Service name.
Sourcepub fn time_in_current_phase(&self) -> Duration
pub fn time_in_current_phase(&self) -> Duration
How long the service has been in its current phase.
Sourcepub fn start_count(&self) -> u32
pub fn start_count(&self) -> u32
Total number of times the service has been started.
Sourcepub fn total_failures(&self) -> u32
pub fn total_failures(&self) -> u32
Total failures over the service’s lifetime.
Sourcepub fn last_error(&self) -> Option<&str>
pub fn last_error(&self) -> Option<&str>
The last error message, if any.
Sourcepub fn termination_reason(&self) -> Option<&TerminationReason>
pub fn termination_reason(&self) -> Option<&TerminationReason>
Why the service terminated (only Some when phase is Terminated).
Sourcepub fn cumulative_running_time(&self) -> Duration
pub fn cumulative_running_time(&self) -> Duration
Cumulative wall-clock time spent in the Running phase.
If the service is currently running, includes time up to now.
Sourcepub fn transition_to_running(&mut self) -> Result<(), TransitionError>
pub fn transition_to_running(&mut self) -> Result<(), TransitionError>
Transition from Starting → Running.
Called when the service’s run() method is entered.
Sourcepub fn transition_to_backing_off(
&mut self,
error: &str,
backoff_duration: Duration,
) -> Result<(), TransitionError>
pub fn transition_to_backing_off( &mut self, error: &str, backoff_duration: Duration, ) -> Result<(), TransitionError>
Transition from Running → BackingOff.
Called when the service’s run() returns an Err.
Sourcepub fn transition_to_restarting(&mut self) -> Result<(), TransitionError>
pub fn transition_to_restarting(&mut self) -> Result<(), TransitionError>
Transition from BackingOff → Starting (retry).
Called when the backoff timer has expired and the supervisor is about to restart the service.
Sourcepub fn transition_to_stopping(&mut self) -> Result<(), TransitionError>
pub fn transition_to_stopping(&mut self) -> Result<(), TransitionError>
Transition to Stopping from any alive phase.
Called when the cancellation token is triggered.
Sourcepub fn transition_to_terminated(
&mut self,
reason: TerminationReason,
) -> Result<(), TransitionError>
pub fn transition_to_terminated( &mut self, reason: TerminationReason, ) -> Result<(), TransitionError>
Transition to Terminated from Stopping, Running, Starting,
or BackingOff.
This is the terminal state; no further transitions are allowed.
Trait Implementations§
Source§impl Clone for ServiceLifecycle
impl Clone for ServiceLifecycle
Source§fn clone(&self) -> ServiceLifecycle
fn clone(&self) -> ServiceLifecycle
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ServiceLifecycle
impl Debug for ServiceLifecycle
Source§impl Display for ServiceLifecycle
impl Display for ServiceLifecycle
Source§impl From<&ServiceLifecycle> for ServiceLifecycleSnapshot
impl From<&ServiceLifecycle> for ServiceLifecycleSnapshot
Source§fn from(lc: &ServiceLifecycle) -> Self
fn from(lc: &ServiceLifecycle) -> Self
Auto Trait Implementations§
impl Freeze for ServiceLifecycle
impl RefUnwindSafe for ServiceLifecycle
impl Send for ServiceLifecycle
impl Sync for ServiceLifecycle
impl Unpin for ServiceLifecycle
impl UnsafeUnpin for ServiceLifecycle
impl UnwindSafe for ServiceLifecycle
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.