CoolBotDataSys/api/routes/health.py

38 lines
968 B
Python
Raw Normal View History

"""健康检查路由"""
from fastapi import APIRouter
from datetime import datetime
from database import db
from api.middleware.response import ApiResponse
router = APIRouter(tags=["health"])
@router.get("/health")
async def health_check():
"""服务健康检查"""
health_status = {
"status": "healthy",
"timestamp": datetime.now().isoformat() + "Z",
"services": {}
}
# 检查数据库
try:
with db.get_cursor() as cursor:
cursor.execute("SELECT 1")
health_status["services"]["database"] = "connected"
except Exception as e:
health_status["services"]["database"] = f"error: {str(e)}"
health_status["status"] = "degraded"
return ApiResponse.success(health_status)
@router.get("/")
async def root():
"""API 根路径"""
return ApiResponse.success({
"name": "CoolBotDataSys API",
"version": "1.0.0",
"docs": "/docs"
})