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