use axum::{extract::State, response::Response, routing::get};
use serde::Serialize;
use super::{format, routes::Routes};
use crate::{app::AppContext, Result};
#[derive(Serialize)]
struct Health {
pub ok: bool,
}
async fn health(State(ctx): State<AppContext>) -> Result<Response> {
let mut is_ok = match ctx.db.ping().await {
Ok(()) => true,
Err(error) => {
tracing::error!(err.msg = %error, err.detail = ?error, "health_db_ping_error");
false
}
};
if let Some(queue) = ctx.queue_provider {
if let Err(error) = queue.ping().await {
tracing::error!(err.msg = %error, err.detail = ?error, "health_redis_ping_error");
is_ok = false;
}
}
format::json(Health { ok: is_ok })
}
pub fn routes() -> Routes {
Routes::new().add("/_health", get(health))
}