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