fix: scheduler

This commit is contained in:
xtaodada 2024-03-11 20:06:59 +08:00
parent ad981468a4
commit 2dfbb66dd1
Signed by: xtaodada
GPG Key ID: 4CBB3F4FA8C85659
3 changed files with 11 additions and 4 deletions

View File

@ -1,5 +1,5 @@
httpx==0.24.1
fastapi~=0.101.1
fastapi~=0.110.0
starlette
uvicorn~=0.23.2
pydantic
@ -8,6 +8,6 @@ coloredlogs
pytz
apscheduler
aiofiles==23.2.1
jinja2==3.1.2
jinja2==3.1.3
beautifulsoup4
lxml

View File

@ -4,6 +4,7 @@ from starlette.middleware.trustedhost import TrustedHostMiddleware
from .env import DOMAIN, DEBUG
from .route import get_routes
from .route.base import UserAgentMiddleware
from .services.scheduler import register_scheduler
app = FastAPI(docs_url=None, redoc_url=None, openapi_url=None)
app.add_middleware(
@ -15,3 +16,4 @@ app.add_middleware(
if not DEBUG:
app.add_middleware(UserAgentMiddleware)
get_routes()
register_scheduler(app)

View File

@ -1,5 +1,10 @@
from apscheduler.schedulers.asyncio import AsyncIOScheduler
from fastapi import FastAPI
scheduler = AsyncIOScheduler(timezone="Asia/ShangHai")
if not scheduler.running:
def register_scheduler(app: "FastAPI"):
@app.on_event("startup")
async def start_event():
scheduler.start()