Skip to content

Commit d9b0e62

Browse files
authored
feat(uptime): check if connection to db works (#3199)
# Description Please include a summary of the changes and the related issue. Please also include relevant motivation and context. ## Checklist before requesting a review Please delete options that are not relevant. - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my code - [ ] I have commented hard-to-understand areas - [ ] I have ideally added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] Any dependent changes have been merged ## Screenshots (if appropriate):
1 parent 758e87e commit d9b0e62

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

backend/api/quivr_api/modules/misc/controller/misc_routes.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
from fastapi import APIRouter
1+
2+
from fastapi import APIRouter, Depends, HTTPException
3+
from quivr_api.logger import get_logger
4+
from quivr_api.modules.dependencies import get_async_session
5+
from sqlmodel.ext.asyncio.session import AsyncSession
6+
from sqlmodel import text
7+
8+
logger = get_logger(__name__)
29

310
misc_router = APIRouter()
411

@@ -12,5 +19,14 @@ async def root():
1219

1320

1421
@misc_router.get("/healthz", tags=["Health"])
15-
async def healthz():
22+
async def healthz(session: AsyncSession = Depends(get_async_session)):
23+
24+
try:
25+
result = await session.execute(text("SELECT 1"))
26+
if not result:
27+
raise HTTPException(status_code=500, detail="Database is not healthy")
28+
except Exception as e:
29+
logger.error(f"Error checking database health: {e}")
30+
raise HTTPException(status_code=500, detail="Database is not healthy")
31+
1632
return {"status": "ok"}

0 commit comments

Comments
 (0)