Files
Edu/services/ai/src/health/health.py
2026-07-08 12:52:48 +08:00

38 lines
986 B
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.
"""健康检查端点ai 服务)。
- GET /healthzliveness仅返回进程存活。
- GET /readyzreadiness简化版返回 ok + TODO待补全 Elasticsearch
连通性与 OpenAI 配置校验。
集成说明:在 FastAPI app 中挂载 router
from health import router as health_router
app.include_router(health_router)
"""
from datetime import UTC, datetime
from fastapi import APIRouter
router = APIRouter()
SERVICE_NAME = "ai"
@router.get("/healthz")
async def healthz() -> dict:
return {"status": "ok", "service": SERVICE_NAME}
@router.get("/readyz")
async def readyz() -> dict:
# TODO: 校验关键依赖
# 1. Elasticsearch 连通性es_client.ping()
# 2. OpenAI 配置API key 是否注入、超时是否合理
# 依赖客户端就绪后再补全检查逻辑,失败时返回 503。
return {
"status": "ok",
"service": SERVICE_NAME,
"timestamp": datetime.now(UTC).isoformat(),
}