From c3f1cc92f7d1060fe35723609f2353540a84c18a Mon Sep 17 00:00:00 2001 From: Damien Degois Date: Sun, 24 Nov 2024 19:28:03 +0100 Subject: [PATCH] perform small db check on startup and get version from env vars --- app.py | 2 ++ db.py | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/app.py b/app.py index 1c8a54f..dff7b60 100755 --- a/app.py +++ b/app.py @@ -1,6 +1,7 @@ #!/usr/bin/env python3 import asyncio import logging +import os import uuid from contextlib import asynccontextmanager from typing import Annotated @@ -46,6 +47,7 @@ async def lifespan(app: FastAPI): app: FastAPI = FastAPI( title="Teams Notifier gitlab-mr-api", + version=os.environ.get("VERSION", "v0.0.0-dev"), lifespan=lifespan, middleware=[ Middleware( diff --git a/db.py b/db.py index c101add..23d7a0a 100644 --- a/db.py +++ b/db.py @@ -48,6 +48,10 @@ async def connect(self): init=self.init_connection, ) + # Simple check at startup, will validate database resolution and creds + async with await self.acquire() as connection: + await connection.fetchval("SELECT 1") + async def init_connection(self, conn: asyncpg.Connection) -> None: log.debug("connecting to database") await conn.set_type_codec("jsonb", encoder=json.dumps, decoder=json.loads, schema="pg_catalog")