#[cfg(any(feature = "cache-memory", feature = "cache-redis"))]
use super::CacheHealthCheck;
#[cfg(any(feature = "db-sqlite", feature = "db-postgres", feature = "db-mysql"))]
use super::DbHealthCheck;
use super::{ConfigHealthCheck, HealthCheck, HealthResult, HealthStatus};
use crate::config::GarrisonConfig;
use std::sync::Arc;
impl ConfigHealthCheck {
pub fn new(config: Arc<GarrisonConfig>) -> Self {
Self { config }
}
}
impl HealthCheck for ConfigHealthCheck {
fn name(&self) -> &str {
"config"
}
fn check(
&self,
) -> std::pin::Pin<Box<dyn std::future::Future<Output = HealthResult<HealthStatus>> + Send>>
{
let config = self.config.clone();
Box::pin(async move {
config.validate()?;
Ok(HealthStatus::Healthy)
})
}
}
#[cfg(any(feature = "cache-memory", feature = "cache-redis"))]
impl CacheHealthCheck {
pub fn new() -> Self {
Self
}
}
#[cfg(any(feature = "cache-memory", feature = "cache-redis"))]
impl Default for CacheHealthCheck {
fn default() -> Self {
Self::new()
}
}
#[cfg(any(feature = "cache-memory", feature = "cache-redis"))]
impl HealthCheck for CacheHealthCheck {
fn name(&self) -> &str {
"cache"
}
fn check(
&self,
) -> std::pin::Pin<Box<dyn std::future::Future<Output = HealthResult<HealthStatus>> + Send>>
{
Box::pin(async {
Ok(HealthStatus::Healthy)
})
}
}
#[cfg(any(feature = "db-sqlite", feature = "db-postgres", feature = "db-mysql"))]
impl DbHealthCheck {
pub fn new() -> Self {
Self
}
}
#[cfg(any(feature = "db-sqlite", feature = "db-postgres", feature = "db-mysql"))]
impl Default for DbHealthCheck {
fn default() -> Self {
Self::new()
}
}
#[cfg(any(feature = "db-sqlite", feature = "db-postgres", feature = "db-mysql"))]
impl HealthCheck for DbHealthCheck {
fn name(&self) -> &str {
"database"
}
fn check(
&self,
) -> std::pin::Pin<Box<dyn std::future::Future<Output = HealthResult<HealthStatus>> + Send>>
{
Box::pin(async {
Ok(HealthStatus::Healthy)
})
}
}