- server: 实现按 workflow_name 的多工作流数据隔离与旧数据库平滑迁移机制 - server: 新增 API Key 认证(auth)、限流中间件(rate_limit)与运维备份接口(admin) - server: 统一 AppError 错误处理体系,重构调度器 scheduler 支持工作流级重置与抢占 - node: 节点 ID 缺失时自动生成随机 UUID,原生支持 `docker compose --scale node=N` 动态扩容 - dashboard: 前端模块化重构(state/api/components),升级 CSS 变量设计系统与 Toast 通知 - docker/docs: 更新 /healthz 健康检查、部署脚本 IP 配置及数据库设计文档
39 lines
1.5 KiB
Rust
39 lines
1.5 KiB
Rust
use super::AppState;
|
||
use axum::{extract::State, response::IntoResponse, Json};
|
||
use serde_json::json;
|
||
|
||
/// 轻量健康检查端点(不走鉴权)。
|
||
///
|
||
/// 供 docker healthcheck、负载均衡、外部监控探测。刻意只返回固定 ok,
|
||
/// 不触碰数据库或调度器,避免健康检查本身拖累系统或因 DB 瞬时锁导致误判不健康。
|
||
pub async fn healthz() -> Result<impl IntoResponse, crate::api::AppError> {
|
||
Ok(Json(json!({ "status": "ok" })))
|
||
}
|
||
|
||
pub async fn get_status(
|
||
State(state): State<AppState>,
|
||
) -> Result<impl IntoResponse, crate::api::AppError> {
|
||
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,
|
||
})))
|
||
}
|