Skip to content

Commit

Permalink
Merge pull request #53 from gardenlinux/check-readiness
Browse files Browse the repository at this point in the history
Add some readiness check
  • Loading branch information
waldiTM authored Dec 18, 2023
2 parents 4bab7fe + 4f8a053 commit dd7f530
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion src/glvd/web/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import collections.abc
import contextlib

from quart import Quart
from quart import Quart, current_app
import sqlalchemy as sa
from sqlalchemy.ext.asyncio import AsyncConnection, AsyncEngine, create_async_engine


Expand Down Expand Up @@ -43,4 +44,27 @@ def create_app():
from .v1_cves import bp as bp_v1_cves
app.register_blueprint(bp_v1_cves)

@app.route('/readiness')
async def readiness() -> tuple[dict, int]:
failed = False
status: dict[str, str | dict] = {}
try:
async with getattr(current_app, 'db_begin')() as conn:
(await conn.execute(sa.text('SELECT TRUE'))).one()
status['db_check'] = {
'status': 'ok',
}
except Exception:
failed = True
status['db_check'] = {
'status': 'failed',
}

if failed:
status['status'] = 'failed'
return (status, 503)
else:
status['status'] = 'ok'
return (status, 200)

return app

0 comments on commit dd7f530

Please sign in to comment.