22 lines
690 B
Python
22 lines
690 B
Python
"""
|
|
健康检查端点,供 Kubernetes liveness/readiness 探针使用。
|
|
详见 documents/设计方案分析与完善版.md §2.12。
|
|
"""
|
|
from django.db import connection
|
|
from django.http import JsonResponse
|
|
|
|
|
|
def healthz(request):
|
|
"""存活探针:仅确认进程可响应请求。"""
|
|
return JsonResponse({"status": "ok"})
|
|
|
|
|
|
def readyz(request):
|
|
"""就绪探针:确认数据库连接可用。"""
|
|
try:
|
|
with connection.cursor() as cursor:
|
|
cursor.execute("SELECT 1")
|
|
except Exception as exc: # pragma: no cover - defensive
|
|
return JsonResponse({"status": "error", "detail": str(exc)}, status=503)
|
|
return JsonResponse({"status": "ok"})
|