feat: cron worker for renewal notifs

This commit is contained in:
2026-08-20 21:28:43 +07:00
parent 0a58a41930
commit b39cae8046
6 changed files with 161 additions and 4 deletions

18
main.py
View File

@@ -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)