您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

12345678910111213141516171819202122232425262728293031323334
  1. use axum::Json;
  2. use axum::extract::State;
  3. use crate::error::ApiResult;
  4. use crate::models::health::{HealthResponse, ReadyResponse};
  5. use crate::state::AppState;
  6. /// Liveness probe. Process is up.
  7. #[utoipa::path(
  8. get,
  9. path = "/health/live",
  10. tag = "health",
  11. responses(
  12. (status = 200, description = "Process is running", body = HealthResponse)
  13. )
  14. )]
  15. pub async fn live(State(state): State<AppState>) -> Json<HealthResponse> {
  16. Json(HealthResponse { status: "ok", service: state.config().app.name.clone() })
  17. }
  18. /// Readiness probe. Database is reachable.
  19. #[utoipa::path(
  20. get,
  21. path = "/health/ready",
  22. tag = "health",
  23. responses(
  24. (status = 200, description = "Database is reachable", body = ReadyResponse),
  25. (status = 500, description = "Database is unreachable", body = crate::error::ErrorBody)
  26. )
  27. )]
  28. pub async fn ready(State(state): State<AppState>) -> ApiResult<Json<ReadyResponse>> {
  29. sqlx::query_scalar::<_, i32>("SELECT 1").fetch_one(state.db()).await?;
  30. Ok(Json(ReadyResponse { status: "ok", database: "up" }))
  31. }