نسخهٔ وب مستقل — پلتفرم نیروی کار هوش مصنوعی
مخزن اختصاصی برنامهٔ وب؛ محتوای پوشهٔ web در ریشهٔ مخزن قرار گرفت. تاریخچهٔ پروژهٔ ربات (agy-bot) در این مخزن وجود ندارد و هیچ وابستگی runtime به آن نیست.
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
"""Health and readiness endpoints."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from fastapi import APIRouter, Depends
|
||||
from sqlalchemy import text
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from app.core.config import settings
|
||||
from app.core.database import get_session
|
||||
from app.infrastructure.adapters.registry import get_model_provider
|
||||
|
||||
router = APIRouter(tags=["health"])
|
||||
|
||||
|
||||
@router.get("/health")
|
||||
async def health() -> dict:
|
||||
"""Liveness. Must stay dependency-free so it answers during a DB outage."""
|
||||
return {"status": "ok", "app": settings.app_name, "env": settings.app_env}
|
||||
|
||||
|
||||
@router.get("/health/ready")
|
||||
async def readiness(session: AsyncSession = Depends(get_session)) -> dict:
|
||||
"""Readiness: verifies the database and reports which adapters are active."""
|
||||
checks: dict[str, object] = {}
|
||||
try:
|
||||
await session.execute(text("SELECT 1"))
|
||||
checks["database"] = "ok"
|
||||
except Exception as exc: # noqa: BLE001 - reported, not raised
|
||||
checks["database"] = f"error: {exc.__class__.__name__}"
|
||||
|
||||
try:
|
||||
model_health = await get_model_provider().health()
|
||||
checks["model_provider"] = "ok" if model_health.ok else f"degraded: {model_health.detail}"
|
||||
except Exception as exc: # noqa: BLE001
|
||||
checks["model_provider"] = f"error: {exc.__class__.__name__}"
|
||||
|
||||
checks["adapters"] = {
|
||||
"ai": settings.ai_default_provider,
|
||||
"git": settings.git_provider,
|
||||
"domain_router": settings.domain_router,
|
||||
"sandbox": settings.sandbox_provider,
|
||||
"payment": settings.payment_provider,
|
||||
}
|
||||
healthy = checks.get("database") == "ok"
|
||||
return {"status": "ok" if healthy else "degraded", "checks": checks}
|
||||
Reference in New Issue
Block a user