Files
vidconf/backend/api/health.py

41 lines
1.2 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""Endpoint для проверки здоровья."""
from fastapi import APIRouter, Depends
from sqlalchemy import text
from sqlalchemy.ext.asyncio import AsyncSession
from core.config import get_settings
from core.db import get_session
from core.redis import redis_client
router = APIRouter()
@router.get("/api/health")
async def health(session: AsyncSession = Depends(get_session)) -> dict[str, bool | str]:
"""Отчет о статусе приложения и связи с БД/Redis.
Поле `version` — версия инстанса (`VIDCONF_VERSION` из `.env`,
пишет `install.sh` из корневого файла `VERSION`); футер админки
берёт его отсюда, а не из версии сборки фронтенда.
"""
db_ok = False
try:
await session.execute(text("SELECT 1"))
db_ok = True
except Exception: # noqa: BLE001
db_ok = False
redis_ok = False
try:
redis_ok = bool(await redis_client.ping())
except Exception: # noqa: BLE001
redis_ok = False
return {
"status": "ok",
"db": db_ok,
"redis": redis_ok,
"version": get_settings().vidconf_version,
}