pub struct LifecycleManager<R: ContainerRuntime + 'static> { /* private fields */ }Expand description
Coordinates the startup, supervision and shutdown of every resource
declared in a LifecyclePlan.
Implementations§
Source§impl<R: ContainerRuntime + 'static> LifecycleManager<R>
impl<R: ContainerRuntime + 'static> LifecycleManager<R>
Sourcepub fn new(plan: LifecyclePlan, runtime: R) -> (Self, Receiver<LifecycleEvent>)
pub fn new(plan: LifecyclePlan, runtime: R) -> (Self, Receiver<LifecycleEvent>)
Build a manager bound to plan and runtime. Returns a fresh
event subscriber alongside; further subscribers can be obtained
from Self::subscribe_events.
Sourcepub async fn start_all(&self) -> Result<(), LifecycleError>
pub async fn start_all(&self) -> Result<(), LifecycleError>
Start every resource in topological order. Independent branches start in parallel. On the first failure, the resources that already started are stopped automatically before the error is returned.
Sourcepub async fn stop_all(&self, grace: Duration) -> Result<(), LifecycleError>
pub async fn stop_all(&self, grace: Duration) -> Result<(), LifecycleError>
Stop every resource in reverse topological order with the given SIGTERM-to-SIGKILL grace window.
Sourcepub async fn run_until_signal(
&self,
grace: Duration,
) -> Result<(), LifecycleError>
pub async fn run_until_signal( &self, grace: Duration, ) -> Result<(), LifecycleError>
Opinionated entry point used by lightshuttle up: starts the
stack, waits for SIGINT or SIGTERM, then stops the stack
cleanly with the configured grace window.
Sourcepub async fn restart_one(&self, resource: &str) -> Result<(), LifecycleError>
pub async fn restart_one(&self, resource: &str) -> Result<(), LifecycleError>
Restart a single resource without touching its dependents.
The target is stopped via SIGTERM (10-second grace window),
its container id and started-at timestamp are cleared, then
start_one is re-run from the same cached spec. Three events
are emitted on the lifecycle channel in order: ResourceStopped,
ResourceStarted, ResourceHealthy.
Dependents keep running. Their watch channels observe the
target’s status going Stopped → Pending → Starting →
Running → Healthy, so callers that depend on the target can
pause their work locally until it is healthy again.
Sourcepub fn subscribe_events(&self) -> Receiver<LifecycleEvent>
pub fn subscribe_events(&self) -> Receiver<LifecycleEvent>
Open a new subscription on the lifecycle event broadcast.
Multiple subscribers can read concurrently. Subscribers that
fall more than [EVENT_CHANNEL_CAPACITY] events behind will
observe a RecvError::Lagged and have to resynchronise.