reifydb_sub_api/
subsystem.rs1use std::any::Any;
5
6use reifydb_core::{interface::version::HasVersion, util::ioc::IocContainer};
7use reifydb_transaction::interceptor::builder::InterceptorBuilder;
8use reifydb_type::Result;
9
10pub trait Subsystem: Any + HasVersion {
15 fn name(&self) -> &'static str;
17 fn start(&mut self) -> Result<()>;
23 fn shutdown(&mut self) -> Result<()>;
31
32 fn is_running(&self) -> bool;
34
35 fn health_status(&self) -> HealthStatus;
40
41 fn as_any(&self) -> &dyn Any;
43
44 fn as_any_mut(&mut self) -> &mut dyn Any;
46}
47
48pub trait SubsystemFactory: Send {
50 fn provide_interceptors(&self, builder: InterceptorBuilder, _ioc: &IocContainer) -> InterceptorBuilder {
51 builder
52 }
53
54 fn create(self: Box<Self>, ioc: &IocContainer) -> Result<Box<dyn Subsystem>>;
55}
56
57#[derive(Debug, Clone, PartialEq)]
58pub enum HealthStatus {
59 Healthy,
60 Warning {
61 description: String,
62 },
63 Degraded {
64 description: String,
65 },
66 Failed {
67 description: String,
68 },
69 Unknown,
70}
71
72impl HealthStatus {
73 pub fn is_healthy(&self) -> bool {
74 matches!(self, HealthStatus::Healthy)
75 }
76
77 pub fn is_failed(&self) -> bool {
78 matches!(self, HealthStatus::Failed { .. })
79 }
80
81 pub fn description(&self) -> &str {
82 match self {
83 HealthStatus::Healthy => "Healthy",
84 HealthStatus::Warning {
85 description: message,
86 } => message,
87 HealthStatus::Degraded {
88 description: message,
89 } => message,
90 HealthStatus::Failed {
91 description: message,
92 } => message,
93 HealthStatus::Unknown => "Unknown",
94 }
95 }
96}