Coverage for polar/health/endpoints.py: 74%
19 statements
« prev ^ index » next coverage.py v7.10.6, created at 2025-12-05 15:52 +0000
« prev ^ index » next coverage.py v7.10.6, created at 2025-12-05 15:52 +0000
1from fastapi import Depends, HTTPException 1a
2from redis import RedisError 1a
3from sqlalchemy import select 1a
4from sqlalchemy.exc import SQLAlchemyError 1a
6from polar.postgres import AsyncSession, get_db_session 1a
7from polar.redis import Redis, get_redis 1a
8from polar.routing import APIRouter 1a
10router = APIRouter(tags=["health"], include_in_schema=False) 1a
13@router.get("/healthz") 1a
14async def healthz( 1ab
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"}