Files
GMG-Smart-Quote/backend/app/api/health.py
T
mgiustini 6c467b6e77 Aggiunta endpoint healtcheck, modelli user,
logiche sicurezza e file config variabili
2026-05-02 14:05:39 +02:00

30 lines
779 B
Python

from fastapi import APIRouter, Depends
from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy import text
import redis.asyncio as aioredis
from app.core.deps import get_db
from app.core.config import settings
router = APIRouter()
@router.get("/health")
async def health_check(db: AsyncSession = Depends(get_db)):
checks = {"status": "ok", "db": "ok", "redis": "ok"}
try:
await db.execute(text("SELECT 1"))
except Exception as e:
checks["db"] = f"error: {str(e)}"
checks["status"] = "degraded"
try:
r = aioredis.from_url(settings.redis_url)
await r.ping()
await r.aclose()
except Exception as e:
checks["redis"] = f"error: {str(e)}"
checks["status"] = "degraded"
return checks