use crate::error::GarrisonResult;
use serde::{Deserialize, Serialize};
use std::sync::Arc;
use std::time::Duration;
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum HealthStatus {
Healthy,
Degraded,
Unhealthy,
}
pub type HealthResult<T> = GarrisonResult<T>;
pub trait HealthCheck: Send + Sync {
fn name(&self) -> &str;
fn check(
&self,
) -> std::pin::Pin<Box<dyn std::future::Future<Output = HealthResult<HealthStatus>> + Send>>;
}
#[derive(Debug, Clone, Serialize)]
pub struct CheckResult {
pub name: String,
pub status: HealthStatus,
#[serde(skip_serializing_if = "Option::is_none")]
pub message: Option<String>,
}
#[derive(Debug, Clone, Serialize)]
pub struct HealthReport {
pub overall: HealthStatus,
pub checks: Vec<CheckResult>,
}
pub struct HealthRegistry {
pub(crate) checks: Vec<Box<dyn HealthCheck>>,
pub(crate) check_timeout: Duration,
}
pub struct ConfigHealthCheck {
pub(crate) config: Arc<crate::config::GarrisonConfig>,
}
#[cfg(any(feature = "cache-memory", feature = "cache-redis"))]
pub struct CacheHealthCheck;
#[cfg(any(feature = "db-sqlite", feature = "db-postgres", feature = "db-mysql"))]
pub struct DbHealthCheck {
#[cfg(any(feature = "db-postgres", feature = "db-mysql"))]
pool: Option<std::sync::Arc<dbnexus::DbPool>>,
#[cfg(not(any(feature = "db-postgres", feature = "db-mysql")))]
_priv: (),
}
pub mod checks;
pub mod probe;
pub mod registry;
pub mod report;
#[cfg(feature = "web-axum")]
pub mod axum_routes;
#[cfg(feature = "web-actix")]
pub mod actix_routes;
#[cfg(feature = "web-warp")]
pub mod warp_routes;
#[cfg(test)]
mod mock;
#[cfg(test)]
mod tests;