pub struct ServiceLifecycle { /* private fields */ }Expand description
Shared process lifecycle and health-probe owner.
Implementations§
Source§impl ServiceLifecycle
impl ServiceLifecycle
Sourcepub fn new(config: ServiceLifecycleConfig) -> Self
pub fn new(config: ServiceLifecycleConfig) -> Self
Creates a new ServiceLifecycle.
Sourcepub fn from_env(service_name: impl Into<Arc<str>>) -> RuntimeResult<Self>
pub fn from_env(service_name: impl Into<Arc<str>>) -> RuntimeResult<Self>
Creates a value from env.
Sourcepub fn config(&self) -> &ServiceLifecycleConfig
pub fn config(&self) -> &ServiceLifecycleConfig
Returns the config.
Sourcepub fn set_observer(
&self,
observer: Arc<dyn ServiceLifecycleObserver>,
) -> RuntimeResult<()>
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.
Sourcepub async fn start(
&self,
service_context: &ChildServiceContext,
) -> RuntimeResult<()>
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.
Sourcepub fn state(&self) -> ServiceLifecycleState
pub fn state(&self) -> ServiceLifecycleState
Returns the state.
Sourcepub fn probe_local_addr(&self) -> Option<SocketAddr>
pub fn probe_local_addr(&self) -> Option<SocketAddr>
Returns the probe local addr.
Sourcepub fn set_dependency_readiness(&self, readiness: DependencyReadiness)
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.
Sourcepub fn dependency_readiness(&self) -> DependencyReadiness
pub fn dependency_readiness(&self) -> DependencyReadiness
Returns the latest aggregate dependency decision independently of lifecycle state.
Sourcepub fn handle_critical_failure(
&self,
failure: &CriticalFailure,
recovery: CriticalFailureRecovery,
)
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.
Sourcepub fn spawn_critical_failure_monitor(
&self,
owner: &TaskSpawner,
failures: &CriticalFailureState,
recovery: CriticalFailureRecovery,
) -> RuntimeResult<TaskId>
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.
Sourcepub fn record_progress(&self)
pub fn record_progress(&self)
Records progress.
Sourcepub fn mark_ready(&self) -> RuntimeResult<()>
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.
Sourcepub fn suspend_readiness_for_maintenance(&self) -> RuntimeResult<()>
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.
Sourcepub fn restore_readiness_after_maintenance(&self) -> RuntimeResult<()>
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.
Sourcepub fn mark_failed(&self)
pub fn mark_failed(&self)
Executes mark failed.
Sourcepub fn mark_stopped(&self)
pub fn mark_stopped(&self)
Executes mark stopped.
Sourcepub fn request_shutdown(&self, reason: ShutdownReason) -> ShutdownRequest
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.
Sourcepub fn shutdown_request(&self) -> Option<ShutdownRequest>
pub fn shutdown_request(&self) -> Option<ShutdownRequest>
Shuts down request.
Sourcepub async fn wait_for_shutdown(&self) -> ShutdownRequest
pub async fn wait_for_shutdown(&self) -> ShutdownRequest
Returns the wait for shutdown.
Sourcepub async fn wait_for_shutdown_signal(&self) -> RuntimeResult<ShutdownRequest>
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.