reifydb_sub_api/
subsystem.rs1use std::any::Any;
5
6use reifydb_core::{interface::version::HasVersion, util::ioc::IocContainer};
7use reifydb_runtime::shutdown::Shutdown;
8use reifydb_transaction::interceptor::builder::InterceptorBuilder;
9use reifydb_value::Result;
10
11pub trait Subsystem: Any + HasVersion + Shutdown {
12 fn name(&self) -> &'static str;
13
14 fn is_running(&self) -> bool;
15
16 fn health_status(&self) -> HealthStatus;
17
18 fn as_any(&self) -> &dyn Any;
19}
20
21pub trait SubsystemFactory: Send {
22 fn provide_interceptors(&self, builder: InterceptorBuilder, _ioc: &IocContainer) -> InterceptorBuilder {
23 builder
24 }
25
26 fn create(self: Box<Self>, ioc: &IocContainer) -> Result<Box<dyn Subsystem>>;
27}
28
29#[derive(Debug, Clone, PartialEq)]
30pub enum HealthStatus {
31 Healthy,
32 Warning {
33 description: String,
34 },
35 Degraded {
36 description: String,
37 },
38 Failed {
39 description: String,
40 },
41 Unknown,
42}
43
44impl HealthStatus {
45 pub fn is_healthy(&self) -> bool {
46 matches!(self, HealthStatus::Healthy)
47 }
48
49 pub fn is_failed(&self) -> bool {
50 matches!(self, HealthStatus::Failed { .. })
51 }
52
53 pub fn description(&self) -> &str {
54 match self {
55 HealthStatus::Healthy => "Healthy",
56 HealthStatus::Warning {
57 description: message,
58 } => message,
59 HealthStatus::Degraded {
60 description: message,
61 } => message,
62 HealthStatus::Failed {
63 description: message,
64 } => message,
65 HealthStatus::Unknown => "Unknown",
66 }
67 }
68}