zhaoqingang
2024-11-15 deaaf771005065d9951a6df4df3e8baade2acca2
main.py
@@ -1,4 +1,5 @@
from contextlib import asynccontextmanager
from apscheduler.schedulers.background import BackgroundScheduler
from fastapi import FastAPI
from app.api.auth import router as auth_router
from app.api.canvas import canvas_router
@@ -11,11 +12,13 @@
from app.api.organization import dept_router
from app.api.report import router as report_router
from app.api.resource import menu_router
from app.api.sync_data import sync_router
from app.api.user import user_router
from app.api.group import group_router
from app.api.role import role_router
from app.models.base_model import init_db
from app.task.fetch_agent import sync_agents, initialize_agents
from app.task.sync_resources import sync_resource
# 使用 Lifespan 事件处理程序
@@ -38,6 +41,16 @@
)
# 创建调度器
scheduler = BackgroundScheduler()
scheduler.add_job(sync_resource,minutes=1, id="sync_resource_data")
scheduler.start()
@app.on_event("shutdown")
async def shutdown_event():
    print("Shutdown event handler")
    scheduler.shutdown()
app.include_router(auth_router, prefix='/api/auth', tags=["auth"])
app.include_router(chat_router, prefix='/api/chat', tags=["chat"])
app.include_router(agent_router, prefix='/api/agent', tags=["agent"])
@@ -52,6 +65,7 @@
app.include_router(knowledge_router, prefix='/api/knowledge', tags=["knowledge"])
app.include_router(dialog_router, prefix='/api/dialog', tags=["dialog"])
app.include_router(canvas_router, prefix='/api/canvas', tags=["canvas"])
app.include_router(sync_router, prefix='/api/sync', tags=["sync"])
if __name__ == "__main__":
    import uvicorn