Skip to main content

lightshuttle_runtime/lifecycle/
status.rs

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