krz/hutch-notify

Notification server for Hutch.

clone: git clone https://gitbay.org/krz/hutch-notify.git

main: app/main.py · raw

 1from contextlib import asynccontextmanager
 2
 3from fastapi import FastAPI
 4from sqlalchemy import text
 5
 6from app.db import engine, Base
 7from app.jobs import start_scheduler, scheduler
 8from app.routers.health import router as health_router
 9from app.routers.devices import router as devices_router
10from app.routers.subscriptions import router as subscriptions_router
11from app.routers.test import router as test_router
12
13
14@asynccontextmanager
15async def lifespan(app: FastAPI):
16    async with engine.begin() as conn:
17        await conn.run_sync(Base.metadata.create_all)
18        await conn.execute(text("select 1"))
19    start_scheduler()
20    yield
21    if scheduler.running:
22        scheduler.shutdown(wait=False)
23    await engine.dispose()
24
25
26app = FastAPI(title="hutch-notify", lifespan=lifespan)
27app.include_router(health_router)
28app.include_router(devices_router)
29app.include_router(subscriptions_router)
30app.include_router(test_router)