myYouTube/backend/app/api/health.py

31 lines
691 B
Python
Raw Permalink Normal View History

import logging
from fastapi import APIRouter, Depends
from sqlalchemy import text
from sqlalchemy.orm import Session
from app.db import get_db
from app.services.metube_client import MeTubeClient
logger = logging.getLogger(__name__)
router = APIRouter()
def _check_database(db: Session) -> str:
try:
db.execute(text("SELECT 1"))
return "ok"
except Exception:
logger.exception("Database healthcheck failed")
return "error"
@router.get("/health")
def health(db: Session = Depends(get_db)) -> dict:
return {
"status": "ok",
"database": _check_database(db),
"metube": "ok" if MeTubeClient().health() else "error",
}