25 lines
715 B
Rust
25 lines
715 B
Rust
use axum::{extract::State, routing::get, Json, Router};
|
|
use redis::AsyncCommands;
|
|
use serde_json::{json, Value};
|
|
|
|
use crate::error::ApiResult;
|
|
use crate::state::AppState;
|
|
|
|
pub fn router() -> Router<AppState> {
|
|
Router::new().route("/ready", get(ready))
|
|
}
|
|
|
|
pub async fn health() -> Json<Value> {
|
|
Json(json!({ "status": "ok" }))
|
|
}
|
|
|
|
pub async fn ready(State(state): State<AppState>) -> ApiResult<Json<Value>> {
|
|
let db_ok = sqlx::query_scalar::<_, i32>("SELECT 1")
|
|
.fetch_one(&state.db)
|
|
.await
|
|
.is_ok();
|
|
let mut redis = state.redis.clone();
|
|
let redis_ok = redis.set::<_, _, ()>("vmall:ready:ping", "1").await.is_ok();
|
|
Ok(Json(json!({ "db": db_ok, "redis": redis_ok })))
|
|
}
|