forked from mtusi2026/mtusi2026lab3
24 lines
568 B
Python
24 lines
568 B
Python
from fastapi import APIRouter, Depends
|
|
from sqlalchemy import text
|
|
from sqlalchemy.orm import Session
|
|
|
|
from ..deps import get_db
|
|
from ..errors import ApiError
|
|
from ..schemas import Health
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
@router.get("/health/live", response_model=Health)
|
|
def live():
|
|
return Health()
|
|
|
|
|
|
@router.get("/health/ready", response_model=Health)
|
|
def ready(db: Session = Depends(get_db)):
|
|
try:
|
|
db.execute(text("SELECT 1"))
|
|
except Exception:
|
|
raise ApiError(503, "unavailable", "База данных недоступна")
|
|
return Health()
|