From b24fbbcb8b42d147fa81b22275e57b5844a1fdc8 Mon Sep 17 00:00:00 2001
From: zhaoqingang <zhaoqg0118@163.com>
Date: 星期三, 25 十二月 2024 09:43:54 +0800
Subject: [PATCH] 问题优化
---
main.py | 28 ++++++++++++++++------------
1 files changed, 16 insertions(+), 12 deletions(-)
diff --git a/main.py b/main.py
index d3bac9a..3a45216 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,7 +22,8 @@
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
+# from app.models.base_model import init_db
+from app.task.fetch_agent import sync_agents, initialize_agents, sync_agents_v2, sync_knowledge
from app.init_config.init_run_data import sync_default_data
@@ -34,6 +35,9 @@
# 鍦ㄥ簲鐢ㄥ惎鍔ㄦ椂鍚屾浠g悊
sync_agents()
await sync_default_data()
+
+ sync_agents_v2()
+ sync_knowledge()
yield
# 鍦ㄥ簲鐢ㄥ叧闂椂鎵ц娓呯悊鎿嶄綔锛堝鏋滈渶瑕侊級
pass
@@ -47,17 +51,17 @@
)
# 璁剧疆 CORS 涓棿浠�
-app.add_middleware(
- CORSMiddleware,
- allow_origins=["*"], # 鍏佽鎵�鏈夊煙鍚嶈法鍩熻闂�
- allow_credentials=True,
- allow_methods=["*"], # 鍏佽鎵�鏈夋柟娉�
- allow_headers=["*"], # 鍏佽鎵�鏈夊ご閮�
-)
+# app.add_middleware(
+# CORSMiddleware,
+# allow_origins=["http://192.168.20.119:9303", "http://192.168.20.119:9301", "http://smartai.com:8293","http://localhost:9303", "http://127.0.0.1:9303","http://localhost:5173","http://192.168.20.158:5173"],
+# allow_credentials=True,
+# allow_methods=["*"], # 鍏佽鎵�鏈夋柟娉�
+# 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=60, id="sync_resource_data")
+scheduler.start()
app.include_router(auth_router, prefix='/api/auth', tags=["auth"])
--
Gitblit v1.8.0