38 lines
986 B
Python
38 lines
986 B
Python
"""健康检查端点(ai 服务)。
|
||
|
||
- GET /healthz:liveness,仅返回进程存活。
|
||
- GET /readyz:readiness,简化版返回 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(),
|
||
}
|