|
12345678910111213141516171819202122232425262728293031323334 |
- use axum::Json;
- use axum::extract::State;
-
- use crate::error::ApiResult;
- use crate::models::health::{HealthResponse, ReadyResponse};
- use crate::state::AppState;
-
- /// Liveness probe. Process is up.
- #[utoipa::path(
- get,
- path = "/health/live",
- tag = "health",
- responses(
- (status = 200, description = "Process is running", body = HealthResponse)
- )
- )]
- pub async fn live(State(state): State<AppState>) -> Json<HealthResponse> {
- Json(HealthResponse { status: "ok", service: state.config().app.name.clone() })
- }
-
- /// Readiness probe. Database is reachable.
- #[utoipa::path(
- get,
- path = "/health/ready",
- tag = "health",
- responses(
- (status = 200, description = "Database is reachable", body = ReadyResponse),
- (status = 500, description = "Database is unreachable", body = crate::error::ErrorBody)
- )
- )]
- pub async fn ready(State(state): State<AppState>) -> ApiResult<Json<ReadyResponse>> {
- sqlx::query_scalar::<_, i32>("SELECT 1").fetch_one(state.db()).await?;
- Ok(Json(ReadyResponse { status: "ok", database: "up" }))
- }
|