use axum::{Json, http::StatusCode}; use serde_json::{json, Value}; use crate::cache::redis::get_redis_manager; #[utoipa::path( get, path = "/health", tag = "misc", responses( ( status = 200, description = "Completely Healthy", body = serde_json::Value, example = json!({ "overall": "healthy", "services": { "api": true, "redis": true, } }) ), ( status = 503, description = "Unhealthy: one or more internal systems are unreachable/unhealthy.", body = serde_json::Value, example = json!({ "overall": "unhealthy", "services": { "api": true, "redis": false, } }) ), ) )] pub async fn fetch_health_data() -> (StatusCode, Json) { let mut overall = "healthy"; let api = true; let response: Option = redis::cmd("PING").query_async(&mut get_redis_manager().await).await.ok(); let redis_status: bool; if let Some("PONG") = response.as_deref() { redis_status = true; } else { redis_status = false; overall = "unhealthy"; } ( if overall == "unhealthy" { StatusCode::SERVICE_UNAVAILABLE } else { StatusCode::OK }, Json(json!({ "overall": overall, "services": { "api": api, "redis": redis_status, } })) ) }