Files
malenia-backend/main.py
2026-08-24 10:22:14 +07:00

32 lines
793 B
Python

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