Skip to main content

reifydb_sub_api/
subsystem.rs

1// SPDX-License-Identifier: Apache-2.0
2// Copyright (c) 2026 ReifyDB
3
4use 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 + Send + Sync {
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 publish_catalog(&self, _ioc: &IocContainer) -> Result<()> {
27		Ok(())
28	}
29
30	fn create(self: Box<Self>, ioc: &IocContainer) -> Result<Box<dyn Subsystem>>;
31}
32
33#[derive(Debug, Clone, PartialEq)]
34pub enum HealthStatus {
35	Healthy,
36	Warning {
37		description: String,
38	},
39	Degraded {
40		description: String,
41	},
42	Failed {
43		description: String,
44	},
45	Unknown,
46}
47
48impl HealthStatus {
49	pub fn is_healthy(&self) -> bool {
50		matches!(self, HealthStatus::Healthy)
51	}
52
53	pub fn is_failed(&self) -> bool {
54		matches!(self, HealthStatus::Failed { .. })
55	}
56
57	pub fn description(&self) -> &str {
58		match self {
59			HealthStatus::Healthy => "Healthy",
60			HealthStatus::Warning {
61				description: message,
62			} => message,
63			HealthStatus::Degraded {
64				description: message,
65			} => message,
66			HealthStatus::Failed {
67				description: message,
68			} => message,
69			HealthStatus::Unknown => "Unknown",
70		}
71	}
72}