//! Health check management. use crate::MonitoringResult; use async_trait::async_trait; use serde::{Deserialize, Serialize}; /// Health check status. #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub enum HealthStatus { Healthy, Degraded, Unhealthy, Unknown, } /// Health check trait. #[async_trait] pub trait HealthCheck: Send + Sync { async fn check(&self) -> MonitoringResult; fn name(&self) -> &str; } /// Health manager for coordinating health checks. pub struct HealthManager { checks: Vec>, } impl std::fmt::Debug for HealthManager { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("HealthManager") .field("checks_count", &self.checks.len()) .finish() } } impl HealthManager { pub async fn new() -> MonitoringResult { Ok(Self { checks: Vec::new() }) } pub fn is_enabled(&self) -> bool { true } pub async fn run_all_checks(&self) -> MonitoringResult<()> { for check in &self.checks { match check.check().await { Ok(status) => { tracing::debug!("Health check '{}': {:?}", check.name(), status); } Err(e) => { tracing::warn!("Health check '{}' failed: {}", check.name(), e); } } } Ok(()) } pub async fn overall_status(&self) -> MonitoringResult { Ok(HealthStatus::Healthy) } }