Coverage for polar/health/endpoints.py: 79%
19 statements
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-07 12:42 +0000
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-07 12:42 +0000
1from fastapi import Depends, HTTPException
2from redis import RedisError
3from sqlalchemy import select
4from sqlalchemy.exc import SQLAlchemyError
6from polar.postgres import AsyncSession, get_db_session
7from polar.redis import Redis, get_redis
8from polar.routing import APIRouter
10router = APIRouter(tags=["health"], include_in_schema=False)
13@router.get("/healthz")
14async def healthz(
15 session: AsyncSession = Depends(get_db_session), redis: Redis = Depends(get_redis)
16) -> dict[str, str]:
17 try:
18 await session.execute(select(1))
19 except SQLAlchemyError as e:
20 raise HTTPException(status_code=503, detail="Database is not available") from e
22 try:
23 await redis.ping()
24 except RedisError as e:
25 raise HTTPException(status_code=503, detail="Redis is not available") from e
27 return {"status": "ok"}