lightshuttle_runtime/lifecycle/status.rs
1//! Per-node status and lifecycle event stream types.
2
3/// Lifecycle status of a single managed resource.
4///
5/// Broadcast through a `tokio::sync::watch` channel so dependents can
6/// wait for their dependencies to become ready without polling.
7#[derive(Debug, Clone, PartialEq, Eq)]
8pub enum NodeStatus {
9 /// The resource has not been started yet.
10 Pending,
11 /// The runtime accepted the start request; the container is booting.
12 Starting,
13 /// The container is up but does not declare a healthcheck or has
14 /// not produced a healthcheck result yet.
15 Running,
16 /// The container is up and reports a successful healthcheck.
17 Healthy,
18 /// The resource entered a terminal failure state with the recorded
19 /// reason.
20 Failed {
21 /// Free-form failure reason for diagnostics.
22 reason: String,
23 },
24 /// The resource has been stopped on request.
25 Stopped,
26}
27
28impl NodeStatus {
29 /// Whether the resource is considered ready for dependents to
30 /// start on top of it.
31 #[must_use]
32 pub fn is_ready(&self) -> bool {
33 matches!(self, Self::Healthy | Self::Running)
34 }
35
36 /// Whether the resource is in a terminal state (failed or stopped).
37 #[must_use]
38 pub fn is_terminal(&self) -> bool {
39 matches!(self, Self::Failed { .. } | Self::Stopped)
40 }
41}
42
43/// Event emitted by [`crate::LifecycleManager`] for consumption by a
44/// CLI, dashboard or test harness.
45#[derive(Debug, Clone)]
46pub enum LifecycleEvent {
47 /// A resource has been created and started by the runtime.
48 ResourceStarted {
49 /// Resource name as declared in the manifest.
50 name: String,
51 /// Container identifier returned by the runtime.
52 container_id: String,
53 },
54 /// A resource passed its healthcheck.
55 ResourceHealthy {
56 /// Resource name.
57 name: String,
58 },
59 /// A resource failed and will not run.
60 ResourceFailed {
61 /// Resource name.
62 name: String,
63 /// Human-readable failure description.
64 error: String,
65 },
66 /// A resource has been stopped cleanly.
67 ResourceStopped {
68 /// Resource name.
69 name: String,
70 },
71 /// Every resource has reached a ready state.
72 StackStarted,
73 /// The manager has started rolling the stack down.
74 StackStopping,
75 /// Every resource has been stopped.
76 StackStopped,
77}