43 lines
1.1 KiB
Python
43 lines
1.1 KiB
Python
from contextlib import asynccontextmanager
|
|
|
|
from fastapi import FastAPI
|
|
from uvicorn.server import logger
|
|
|
|
def init_database():
|
|
from model import create_db_and_tables
|
|
|
|
logger.info("[数据库] 初始化数据库 📦")
|
|
create_db_and_tables()
|
|
logger.info("[数据库] 数据库初始化完成 ✅")
|
|
|
|
def init_scheduler(app : FastAPI):
|
|
from scheduler import init_scheduler_router
|
|
logger.info("[定时任务] 初始化定时任务 📦")
|
|
init_scheduler_router(app)
|
|
logger.info("[定时任务] 定时任务初始化完成 ✅")
|
|
|
|
|
|
def active_config():
|
|
logger.info(f"[激活配置] 加载配置 ⚙️")
|
|
from config import setting # noqa
|
|
|
|
|
|
def import_router(app: FastAPI):
|
|
logger.info(f"[导入路由] 开始导入路由 🛣️")
|
|
from router import router
|
|
|
|
app.include_router(router)
|
|
logger.info(f"[导入路由] 路由导入完成 ✅")
|
|
|
|
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(app: FastAPI):
|
|
logger.info(f"[生命周期] 应用启动 🚀")
|
|
active_config()
|
|
init_database()
|
|
import_router(app)
|
|
init_scheduler(app)
|
|
yield
|
|
logger.info(f"[生命周期] 应用关闭 🔧✅")
|