Commit f1184f7f authored by Kantz's avatar Kantz
Browse files

health-check gefixed

parent 217c2686
from __future__ import annotations
import asyncio
import logging
from threading import Lock
from typing import Any, Dict
......@@ -177,17 +176,15 @@ async def _probe_mcp_server() -> dict:
return {"status": "error", "url": url, "detail": str(exc)}
def _check_mcp() -> dict:
async def _check_mcp() -> dict:
if not config.get_llm_tool_use_enabled():
return {"status": "disabled"}
return asyncio.run(_probe_mcp_server())
return await _probe_mcp_server()
@router.get("/api/health")
def health() -> Dict[str, Any]:
async def _health_payload() -> Dict[str, Any]:
services = {
**_check_selected_llm_provider(),
"mcp": _check_mcp(),
"mcp": await _check_mcp(),
"postgres": _check_postgres(),
"llm_quota": _check_llm_quota(),
}
......@@ -198,6 +195,11 @@ def health() -> Dict[str, Any]:
return {"status": overall, "services": services}
@router.get("/api/health")
async def health() -> Dict[str, Any]:
return await _health_payload()
@router.get("/api/health/ready", response_model=None)
def readiness() -> Any:
state = get_readiness_state()
......@@ -206,8 +208,8 @@ def readiness() -> Any:
return JSONResponse(status_code=503, content=state)
def run_startup_checks() -> Dict[str, Any]:
result = health()
async def run_startup_checks() -> Dict[str, Any]:
result = await _health_payload()
status = result.get("status")
if status == "ok":
logger.info("Startup health check OK")
......
......@@ -15,7 +15,7 @@ logger = logging.getLogger(__name__)
@asynccontextmanager
async def lifespan(_app: FastAPI):
health.set_readiness_starting()
startup_result = health.run_startup_checks()
startup_result = await health.run_startup_checks()
if startup_result.get("status") != "ok":
health.set_readiness_failed(
"Startup health checks degraded",
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment