use super::AppState; use axum::{extract::State, response::IntoResponse, Json}; use serde_json::json; /// 轻量健康检查端点(不走鉴权)。 /// /// 供 docker healthcheck、负载均衡、外部监控探测。刻意只返回固定 ok, /// 不触碰数据库或调度器,避免健康检查本身拖累系统或因 DB 瞬时锁导致误判不健康。 pub async fn healthz() -> Result { Ok(Json(json!({ "status": "ok" }))) } pub async fn get_status( State(state): State, ) -> Result { let nodes = state.db.get_active_nodes().await.unwrap_or_default(); let total_active_slots: i32 = nodes.iter().map(|n| n.active_slots).sum(); let total_max_slots: i32 = nodes.iter().map(|n| n.max_slots).sum(); // dashboard 全局概览:聚合全部工作流的 grid_points(多工作流分区后仍提供全局合计)。 // 若需单工作流进度,可扩展为按 workflow 查询参数分别聚合。 let grid_stats = state .db .get_grid_summary_stats(None) .await .unwrap_or(serde_json::json!({ "total": 0, "pending": 0, "running": 0, "converged": 0, "failed": 0 })); Ok(Json(json!({ "status": "online", "nodes_online": nodes.len(), "total_active_slots": total_active_slots, "total_max_slots": total_max_slots, "nodes": nodes, "grid_stats": grid_stats, }))) }