Add readiness probe endpoint with DB connectivity check

This commit is contained in:
Oliver Neumann 2026-04-02 09:00:00 +00:00
parent 9cab38befb
commit b1f809708e

View file

@ -4,3 +4,12 @@ use serde_json::{json, Value};
pub async fn health_check() -> (StatusCode, Json<Value>) {
(StatusCode::OK, Json(json!({ "status": "ok", "version": env!("CARGO_PKG_VERSION") })))
}
pub async fn readiness_check(
axum::extract::State(pool): axum::extract::State<sqlx::PgPool>,
) -> axum::http::StatusCode {
match sqlx::query("SELECT 1").fetch_one(&pool).await {
Ok(_) => axum::http::StatusCode::OK,
Err(_) => axum::http::StatusCode::SERVICE_UNAVAILABLE,
}
}