spore-commons/node/spore_node/api/routers/health.py

36 lines
782 B
Python

"""Health check endpoint."""
from fastapi import APIRouter
from spore_node.db.connection import get_pool
router = APIRouter(tags=["health"])
@router.get("/")
async def root():
"""Root endpoint — redirect to docs."""
return {
"name": "Spore Agent Commons",
"version": "0.1.0",
"docs": "/docs",
"health": "/health",
}
@router.get("/health")
async def health():
"""Node health check with DB connectivity."""
db_ok = False
try:
pool = get_pool()
async with pool.acquire() as conn:
await conn.fetchval("SELECT 1")
db_ok = True
except Exception:
pass
return {
"status": "ok" if db_ok else "degraded",
"db": "connected" if db_ok else "disconnected",
}