1use std::collections::HashMap;
4use std::sync::Arc;
5
6use async_trait::async_trait;
7
8use crate::rpc::BoxFuture;
9
10#[derive(Debug, Clone)]
12pub struct HealthStatus {
13 pub healthy: bool,
15 pub message: Option<String>,
17}
18
19impl HealthStatus {
20 pub fn ok() -> Self {
21 Self {
22 healthy: true,
23 message: None,
24 }
25 }
26
27 pub fn degraded(msg: impl Into<String>) -> Self {
28 Self {
29 healthy: false,
30 message: Some(msg.into()),
31 }
32 }
33}
34
35pub type HealthCheckFn = Arc<dyn Fn() -> BoxFuture<'static, HealthStatus> + Send + Sync>;
37
38#[async_trait]
40pub trait HealthRegistry: Send + Sync + 'static {
41 async fn register(&self, plugin_name: String, check: HealthCheckFn);
43
44 async fn check_all(&self) -> HashMap<String, HealthStatus>;
46}