Add readiness probe endpoint with DB connectivity check
This commit is contained in:
parent
9cab38befb
commit
b1f809708e
1 changed files with 9 additions and 0 deletions
|
|
@ -4,3 +4,12 @@ use serde_json::{json, Value};
|
||||||
pub async fn health_check() -> (StatusCode, Json<Value>) {
|
pub async fn health_check() -> (StatusCode, Json<Value>) {
|
||||||
(StatusCode::OK, Json(json!({ "status": "ok", "version": env!("CARGO_PKG_VERSION") })))
|
(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,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue