import asyncio from contextlib import asynccontextmanager, suppress from fastapi import FastAPI from routes import routers from services.notifications import run_subscription_notifications @asynccontextmanager async def lifespan(_: FastAPI): task = asyncio.create_task(run_subscription_notifications()) try: yield finally: task.cancel() with suppress(asyncio.CancelledError): await task app = FastAPI(debug=True, lifespan=lifespan) for r in routers: app.include_router(r)