appcore_ops/health.rs
1// =============================================================================
2// #######
3// ### ### F: health.rs
4// ## ## ## ## P: AppCore-Runtime
5// ## ##
6// C: 2026/05/31 13:38:42 by dnettoRaw
7// ## ## ## ## U: 2026/07/23 23:50:45 by dnettoRaw
8// ########### S: 1.0.1-rc.8
9// =============================================================================
10
11//! Health status contracts for runtime observability checks.
12
13/// Coarse runtime health status.
14#[derive(Debug, Clone, Copy, PartialEq, Eq)]
15pub enum HealthStatus {
16 /// Component operates normally.
17 Healthy,
18 /// Component remains available with reduced guarantees.
19 Degraded,
20 /// Component allows only restricted operations.
21 Restricted,
22 /// Component is stopped.
23 Stopped,
24}
25
26/// Result of a health check.
27#[derive(Debug, Clone, PartialEq, Eq)]
28pub struct HealthReport {
29 /// Coarse health status.
30 pub status: HealthStatus,
31 /// Optional non-sensitive detail.
32 pub message: Option<String>,
33}
34
35/// Contract for a component that can report health.
36pub trait HealthCheck {
37 /// Returns the stable check name.
38 fn name(&self) -> &str;
39 /// Produces a current health report.
40 fn check(&self) -> HealthReport;
41}
42
43/// Basic static health check for local runtime bootstrap/status.
44#[derive(Debug, Clone, PartialEq, Eq)]
45pub struct BasicHealthCheck {
46 name: String,
47 report: HealthReport,
48}
49
50impl BasicHealthCheck {
51 /// Creates a check that returns a fixed report.
52 pub fn new(name: impl Into<String>, report: HealthReport) -> Self {
53 Self {
54 name: name.into(),
55 report,
56 }
57 }
58}
59
60impl HealthCheck for BasicHealthCheck {
61 fn name(&self) -> &str {
62 &self.name
63 }
64
65 fn check(&self) -> HealthReport {
66 self.report.clone()
67 }
68}
69
70#[cfg(test)]
71#[path = "health_tests.rs"]
72mod tests;