feat: cron worker for renewal notifs
This commit is contained in:
18
main.py
18
main.py
@@ -1,8 +1,24 @@
|
||||
import asyncio
|
||||
from contextlib import asynccontextmanager, suppress
|
||||
|
||||
from fastapi import FastAPI
|
||||
|
||||
from routes import routers
|
||||
from services.notifications import run_subscription_notifications
|
||||
|
||||
app = FastAPI(debug=True)
|
||||
|
||||
@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)
|
||||
|
||||
Reference in New Issue
Block a user