From 6eb15dc18bf305a6d9396f95c94867127922e1f6 Mon Sep 17 00:00:00 2001 From: xuyonghao <898441624@qq.com> Date: 星期三, 12 二月 2025 18:37:38 +0800 Subject: [PATCH] resource表更新 --- main.py | 32 +++++++++++++++++++++----------- 1 files changed, 21 insertions(+), 11 deletions(-) diff --git a/main.py b/main.py index 21dad54..a37c34f 100644 --- a/main.py +++ b/main.py @@ -1,5 +1,5 @@ from contextlib import asynccontextmanager -# from apscheduler.schedulers.background import BackgroundScheduler +from apscheduler.schedulers.background import BackgroundScheduler from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware from starlette.staticfiles import StaticFiles @@ -22,25 +22,34 @@ from app.api.user import user_router from app.api.group import group_router from app.api.role import role_router -from app.task.fetch_agent import sync_agents, initialize_agents, sync_agents_v2 +from app.models.base_model import init_db +from app.task.delete_execl_file import delete_file_after_delay +# from app.models.base_model import init_db +from app.task.fetch_agent import sync_agents, initialize_agents, sync_agents_v2, sync_knowledge, \ + sync_resources_from_json from app.init_config.init_run_data import sync_default_data + +init_db() # 浣跨敤 Lifespan 浜嬩欢澶勭悊绋嬪簭 @asynccontextmanager async def lifespan(app: FastAPI): # 鍒濆鍖栦唬鐞� - initialize_agents() - # 鍦ㄥ簲鐢ㄥ惎鍔ㄦ椂鍚屾浠g悊 - sync_agents() - await sync_default_data() + # initialize_agents() + # # 鍦ㄥ簲鐢ㄥ惎鍔ㄦ椂鍚屾浠g悊 + # sync_agents() + + await sync_default_data() sync_agents_v2() + sync_knowledge() + sync_resources_from_json() yield # 鍦ㄥ簲鐢ㄥ叧闂椂鎵ц娓呯悊鎿嶄綔锛堝鏋滈渶瑕侊級 pass -# init_db() + app = FastAPI( title="basic_rag_gateway", version="0.1", @@ -57,10 +66,10 @@ # allow_headers=["*"], # 鍏佽鎵�鏈夊ご閮� # ) # 鍒涘缓璋冨害鍣� -# scheduler = BackgroundScheduler() -# scheduler.add_job(sync_resource, 'interval', minutes=1, id="sync_resource_data") -# scheduler.start() - +scheduler = BackgroundScheduler() +scheduler.add_job(sync_agents_v2, 'interval', minutes=10, id="sync_resource_data") +# scheduler.add_job(delete_file_after_delay, 'interval', minutes=10, id="delete_file_after_delay") +scheduler.start() app.include_router(auth_router, prefix='/api/auth', tags=["auth"]) app.include_router(chat_router, prefix='/api/chat', tags=["chat"]) @@ -83,4 +92,5 @@ if __name__ == "__main__": import uvicorn + uvicorn.run(app, host="0.0.0.0", port=9201) -- Gitblit v1.8.0