Skip to content

Commit 6c86245

Browse files
authored
Merge pull request #2 from teams-notifier/db-check-and-version
perform small db check on startup and get version from env vars
2 parents 13397d2 + c3f1cc9 commit 6c86245

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

app.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env python3
22
import asyncio
33
import logging
4+
import os
45
import uuid
56
from contextlib import asynccontextmanager
67
from typing import Annotated
@@ -46,6 +47,7 @@ async def lifespan(app: FastAPI):
4647

4748
app: FastAPI = FastAPI(
4849
title="Teams Notifier gitlab-mr-api",
50+
version=os.environ.get("VERSION", "v0.0.0-dev"),
4951
lifespan=lifespan,
5052
middleware=[
5153
Middleware(

db.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ async def connect(self):
4848
init=self.init_connection,
4949
)
5050

51+
# Simple check at startup, will validate database resolution and creds
52+
async with await self.acquire() as connection:
53+
await connection.fetchval("SELECT 1")
54+
5155
async def init_connection(self, conn: asyncpg.Connection) -> None:
5256
log.debug("connecting to database")
5357
await conn.set_type_codec("jsonb", encoder=json.dumps, decoder=json.loads, schema="pg_catalog")

0 commit comments

Comments
 (0)