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