Files
PlantAI-rag-new/sdk/app/routers/health.py
T
jerryandClaude Fable 5 0875bb036c P0/M1: 四部分重构——frontend→ui、backend→sdk 改名 + 引用修复 + 骨架
- git mv 保留历史:ui/(Vue3+Vite)、sdk/(BFF 中间层)
- 路径语义修正:db_path/figures_cache 改相对 sdk/(BFF cwd),
  历史库 sdk/backend/data 迁移至 sdk/data/(会话/图片缓存无损)
- 引用修复 ~15 处:config.py、deploy/*.sh、vitest/playwright 配置、
  单测导入路径、docs、README、gitignore、.env.example
- 骨架:agent/{qa,methodology,legacy-rag,vendor}、knowledge/manifest.yaml、
  tooling/{compile,kb,crypto,assemble,audit,tools,scripts} + README
- 门禁验证:sdk pytest 125 通过、ui vitest 158 通过、
  生产 BFF 脚本重启四上游全绿 + 静态托管 + 会话库无损

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-31 12:56:47 +08:00

36 lines
1.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""routers/health.py —— GET /api/health(API.md §3)。
并发探测 7920、8000、7900 与 Neo4j(1s 超时,5s 缓存),外加 db 状态。
返回 `{status, version, upstreams, db}`;健康接口不包错误信封(API.md §1 例外)。
"""
from __future__ import annotations
from fastapi import APIRouter
from ..config import get_settings
from ..db import db
from ..upstream import probe_all
router = APIRouter(prefix="/api", tags=["health"])
async def _db_status() -> dict:
try:
rows = await db.fetchall("SELECT COUNT(*) AS n FROM sessions")
return {"ok": True, "sessions": rows[0]["n"] if rows else 0}
except Exception:
return {"ok": False, "sessions": 0}
@router.get("/health")
async def health() -> dict:
upstreams = await probe_all()
db_status = await _db_status()
degraded = not all(u.get("ok") for u in upstreams.values()) or not db_status.get("ok")
return {
"status": "degraded" if degraded else "ok",
"version": get_settings().version,
"upstreams": upstreams,
"db": db_status,
}