You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
929 B
Python
37 lines
929 B
Python
from contextlib import asynccontextmanager
|
|
import uvicorn
|
|
from fastapi import FastAPI
|
|
from api import sync_message
|
|
from util import config
|
|
from scheduler.scheduler_module import start_scheduler, shutdown_scheduler
|
|
|
|
|
|
from util.database import init_db
|
|
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(app: FastAPI):
|
|
"""
|
|
FastAPI 应用的生命周期管理器。
|
|
在应用启动时初始化数据库并启动调度器,在应用关闭时关闭调度器。
|
|
"""
|
|
# 在应用启动时初始化数据库
|
|
init_db()
|
|
|
|
# 启动调度器
|
|
start_scheduler()
|
|
|
|
yield
|
|
|
|
# 在应用关闭时关闭调度器
|
|
shutdown_scheduler()
|
|
|
|
app = FastAPI(lifespan=lifespan)
|
|
|
|
app.include_router(sync_message.router, prefix="/api/v1", tags=["SyncMessage"])
|
|
app.include_router(config.router, prefix="/api/v1", tags=["config"])
|
|
|
|
|
|
if __name__ == "__main__":
|
|
uvicorn.run("main:app", host="0.0.0.0", port=18000, reload=False)
|