use std::collections::HashMap;
use std::sync::Arc;
use async_trait::async_trait;
use crate::rpc::BoxFuture;
#[derive(Debug, Clone)]
pub struct HealthStatus {
pub healthy: bool,
pub message: Option<String>,
}
impl HealthStatus {
pub fn ok() -> Self {
Self {
healthy: true,
message: None,
}
}
pub fn degraded(msg: impl Into<String>) -> Self {
Self {
healthy: false,
message: Some(msg.into()),
}
}
}
pub type HealthCheckFn = Arc<dyn Fn() -> BoxFuture<'static, HealthStatus> + Send + Sync>;
#[async_trait]
pub trait HealthRegistry: Send + Sync + 'static {
async fn register(&self, plugin_name: String, check: HealthCheckFn);
async fn check_all(&self) -> HashMap<String, HealthStatus>;
}