Skip to main content

ServiceLifecycle

Struct ServiceLifecycle 

Source
pub struct ServiceLifecycle { /* private fields */ }
Expand description

Shared process lifecycle and health-probe owner.

Implementations§

Source§

impl ServiceLifecycle

Source

pub fn new(config: ServiceLifecycleConfig) -> Self

Creates a new ServiceLifecycle.

Source

pub fn from_env(service_name: impl Into<Arc<str>>) -> RuntimeResult<Self>

Creates a value from env.

Source

pub fn config(&self) -> &ServiceLifecycleConfig

Returns the config.

Source

pub fn set_observer( &self, observer: Arc<dyn ServiceLifecycleObserver>, ) -> RuntimeResult<()>

Binds one observer before the first state transition and emits Starting.

§Errors

Returns an error if an observer is already installed or the lifecycle has left Starting. Installation is serialized with state transitions.

Source

pub async fn start( &self, service_context: &ChildServiceContext, ) -> RuntimeResult<()>

Starts the progress heartbeat and optional HTTP probe server under a dedicated component task group of service_context.

§Errors

Returns an error when called twice, when the listener cannot bind, or when either owned service task cannot be registered. A failed start cancels and awaits every task registered by that attempt before making the lifecycle retryable.

Source

pub fn state(&self) -> ServiceLifecycleState

Returns the state.

Source

pub fn probe_local_addr(&self) -> Option<SocketAddr>

Returns the probe local addr.

Source

pub fn is_ready(&self) -> bool

Returns whether ready.

Source

pub fn set_dependency_readiness(&self, readiness: DependencyReadiness)

Publishes the aggregate dependency decision without changing lifecycle state. A healthy dependency cannot undo maintenance, drain, failure, or stop.

Source

pub fn dependency_readiness(&self) -> DependencyReadiness

Returns the latest aggregate dependency decision independently of lifecycle state.

Source

pub fn handle_critical_failure( &self, failure: &CriticalFailure, recovery: CriticalFailureRecovery, )

Applies the handling policy for one critical task failure.

Dependency readiness is revoked first, because a process whose critical work failed must stop advertising itself as ready even when it keeps making progress. The remaining effects are the caller’s policy: this method never decides on its own whether the process fails or asks for an ordered shutdown.

Source

pub fn spawn_critical_failure_monitor( &self, owner: &TaskSpawner, failures: &CriticalFailureState, recovery: CriticalFailureRecovery, ) -> RuntimeResult<TaskId>

Spawns a monitor that applies recovery when a critical failure is pending.

owner must be an owner outside the group of the monitored tasks, because a poisoned group can neither spawn nor run its own monitor. The monitor takes each pending failure before handling it, so repeated failures are handled in sequence rather than replayed.

§Errors

Returns an error when owner is shutting down or closed.

Source

pub fn is_live(&self) -> bool

Returns whether live.

Source

pub fn record_progress(&self)

Records progress.

Source

pub fn mark_ready(&self) -> RuntimeResult<()>

Marks startup dependencies ready without allowing a drain request to be reversed.

§Errors

Returns an error when shutdown or failure already began.

Source

pub fn suspend_readiness_for_maintenance(&self) -> RuntimeResult<()>

Temporarily removes this process from readiness during a reversible maintenance operation.

This does not alter the process lifecycle state. A real shutdown request remains irreversible and prevents a later readiness restore.

§Errors

Returns an error unless the process is ready and shutdown has not begun.

Source

pub fn restore_readiness_after_maintenance(&self) -> RuntimeResult<()>

Restores readiness after a reversible maintenance operation.

§Errors

Returns an error when shutdown, failure, or stop has begun.

Source

pub fn mark_failed(&self)

Executes mark failed.

Source

pub fn mark_stopped(&self)

Executes mark stopped.

Source

pub fn request_shutdown(&self, reason: ShutdownReason) -> ShutdownRequest

Records the first shutdown request and returns its immutable deadline.

Repeated pre-stop or signal delivery is idempotent and cannot extend the budget.

Source

pub fn shutdown_request(&self) -> Option<ShutdownRequest>

Shuts down request.

Source

pub async fn wait_for_shutdown(&self) -> ShutdownRequest

Returns the wait for shutdown.

Source

pub async fn wait_for_shutdown_signal(&self) -> RuntimeResult<ShutdownRequest>

Waits for pre-stop or an operating-system termination signal.

§Errors

Returns the platform signal registration error without inventing a successful signal.

Trait Implementations§

Source§

impl Clone for ServiceLifecycle

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ServiceLifecycle

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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<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