use super::{HealthCheck, HealthResult, HealthStatus};
use crate::error::GarrisonError;
pub struct AlwaysHealthy;
impl HealthCheck for AlwaysHealthy {
fn name(&self) -> &str {
"always-healthy"
}
fn check(
&self,
) -> std::pin::Pin<Box<dyn std::future::Future<Output = HealthResult<HealthStatus>> + Send>>
{
Box::pin(async { Ok(HealthStatus::Healthy) })
}
}
pub struct AlwaysUnhealthy;
impl HealthCheck for AlwaysUnhealthy {
fn name(&self) -> &str {
"always-unhealthy"
}
fn check(
&self,
) -> std::pin::Pin<Box<dyn std::future::Future<Output = HealthResult<HealthStatus>> + Send>>
{
Box::pin(async {
Err(GarrisonError::Internal(
"dependency unavailable".to_string(),
))
})
}
}
pub struct AlwaysDegraded;
impl HealthCheck for AlwaysDegraded {
fn name(&self) -> &str {
"always-degraded"
}
fn check(
&self,
) -> std::pin::Pin<Box<dyn std::future::Future<Output = HealthResult<HealthStatus>> + Send>>
{
Box::pin(async { Ok(HealthStatus::Degraded) })
}
}
pub struct PanickingCheck;
impl HealthCheck for PanickingCheck {
fn name(&self) -> &str {
"panicking"
}
fn check(
&self,
) -> std::pin::Pin<Box<dyn std::future::Future<Output = HealthResult<HealthStatus>> + Send>>
{
Box::pin(async { panic!("probe blew up") })
}
}
pub struct HangingCheck;
impl HealthCheck for HangingCheck {
fn name(&self) -> &str {
"hanging"
}
fn check(
&self,
) -> std::pin::Pin<Box<dyn std::future::Future<Output = HealthResult<HealthStatus>> + Send>>
{
Box::pin(async {
tokio::time::sleep(std::time::Duration::from_secs(30)).await;
Ok(HealthStatus::Healthy)
})
}
}