feat(task): 后台任务改为apscheduler执行

This commit is contained in:
xingc
2025-05-12 20:08:50 +08:00
parent eec9d3048c
commit 680c5c2b63
9 changed files with 74 additions and 11 deletions

View File

@@ -13,6 +13,7 @@ from fastapi_limiter import FastAPILimiter
from config import settings
from core.base.exceptions import CardBookException
from core.base.scheduler import scheduler
from core.db.engine import get_cache
from core.routers.route import routers
from core.routers.chat.handlers import socket_manager
@@ -44,6 +45,7 @@ def create_app() -> FastAPI:
@app.on_event('startup')
async def startup_event():
redis_conn = await get_cache()
scheduler.start()
await FastAPILimiter.init(redis_conn)
logger.info(f'Application ``{settings.NAME}`` is started')
@@ -51,6 +53,7 @@ def create_app() -> FastAPI:
async def shutdown_event():
logger.info(f'Application ``{settings.NAME}`` is closed')
await socket_manager.pubsub_client.disconnect()
scheduler.shutdown()
@app.exception_handler(HTTPException)
async def http_exception_handler(request: Request, exc: HTTPException):