Skip to main content

appcore_supervisor/
events.rs

1// =============================================================================
2//        #######
3//     ###       ###     F: events.rs
4//    ##   ## ##   ##    P: AppCore-Runtime
5//         ## ##
6//                       C: 2026/07/24 13:18:47 by dnettoRaw
7//    ##   ## ##   ##    U: 2026/07/24 13:18:47 by dnettoRaw
8//      ###########      S: 1.0.1-rc.8
9// =============================================================================
10
11//! Bounded, non-sensitive supervisor and watchdog events.
12
13/// Stable kind emitted for supervisor and watchdog state changes.
14#[derive(Debug, Clone, Copy, PartialEq, Eq)]
15pub enum SupervisorEventKind {
16    /// A service started.
17    ServiceStarted,
18    /// A service stopped.
19    ServiceStopped,
20    /// A restart was accepted into the bounded schedule.
21    ServiceRestartScheduled,
22    /// A service restarted.
23    ServiceRestarted,
24    /// A service failed.
25    ServiceFailed,
26    /// A degraded or failed service recovered.
27    ServiceRecovered,
28    /// A service instance outlived its shutdown timeout.
29    ServiceOrphaned,
30    /// A service exhausted its restart budget.
31    RestartBudgetExceeded,
32    /// A service requires operator intervention.
33    ServiceQuarantined,
34    /// A reconciliation cycle completed.
35    SupervisorProgressed,
36    /// The watchdog detected absent reconciliation progress.
37    SupervisorStalled,
38    /// Reconciliation resumed after a stall.
39    SupervisorRecovered,
40}
41
42/// One bounded, non-sensitive supervisor event.
43#[derive(Debug, Clone, PartialEq, Eq)]
44pub struct SupervisorEvent {
45    /// Service identifier, or `supervisor` for process-level events.
46    pub service_id: String,
47    /// Stable event kind.
48    pub kind: SupervisorEventKind,
49    /// Event time in Unix milliseconds.
50    pub timestamp_ms: u64,
51    /// Restart attempt or reconcile sequence associated with the event.
52    pub attempt: u64,
53    /// Controlled reason code without service payloads or secrets.
54    pub reason: String,
55    /// Stable previous state label.
56    pub previous_state: String,
57    /// Stable new state label.
58    pub new_state: String,
59    /// Process-local trace identifier.
60    pub trace_id: String,
61}
62
63impl SupervisorEvent {
64    pub(crate) fn new(
65        service_id: impl Into<String>,
66        kind: SupervisorEventKind,
67        timestamp_ms: u64,
68        attempt: u64,
69        transition: (&str, &str),
70        reason: &str,
71        trace_id: String,
72    ) -> Self {
73        Self {
74            service_id: service_id.into(),
75            kind,
76            timestamp_ms,
77            attempt,
78            reason: reason.to_string(),
79            previous_state: transition.0.to_string(),
80            new_state: transition.1.to_string(),
81            trace_id,
82        }
83    }
84}