From 75c06f31eb7974bef57066b6a11d15e785670b54 Mon Sep 17 00:00:00 2001 From: "Kalman.CHENG" <123204464@qq.com> Date: Wed, 16 Jul 2025 09:06:08 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=99=E8=82=B2=E5=9E=82=E7=9B=B4=E9=A2=86?= =?UTF-8?q?=E5=9F=9F=E5=A4=A7=E6=A8=A1=E5=9E=8B=E5=B9=B3=E5=8F=B0=20modify?= =?UTF-8?q?=20by=20Kalman.CHENG=20=E2=98=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dsAiTeachingModel/main.py | 2 +- dsAiTeachingModel/tasks/BackgroundTasks.py | 6 ++++-- dsAiTeachingModel/utils/Database.py | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/dsAiTeachingModel/main.py b/dsAiTeachingModel/main.py index d7b3cfdc..72613efa 100644 --- a/dsAiTeachingModel/main.py +++ b/dsAiTeachingModel/main.py @@ -23,7 +23,7 @@ async def lifespan(app: FastAPI): await init_database() # 启动异步任务 - asyncio.create_task(train_document_task()) + # asyncio.create_task(train_document_task()) yield await shutdown_database() diff --git a/dsAiTeachingModel/tasks/BackgroundTasks.py b/dsAiTeachingModel/tasks/BackgroundTasks.py index d43dc190..b5eb4a24 100644 --- a/dsAiTeachingModel/tasks/BackgroundTasks.py +++ b/dsAiTeachingModel/tasks/BackgroundTasks.py @@ -12,11 +12,13 @@ WORKING_DIR = f"./output" # 后台任务,监控是否有新的未训练的文档进行训练 async def train_document_task(): print("线程5秒后开始运行【监控是否有新的未训练的文档进行训练】") + num = 1 await asyncio.sleep(5) # 使用 asyncio.sleep 而不是 time.sleep # 这里放置你的线程逻辑 while True: # 这里可以放置你的线程要执行的代码 - logging.info("开始查询是否有未训练的文档") + logging.info("开始查询是否有未训练的文档:" + str(num)) + num = num + 1 no_train_document_sql: str = " SELECT * FROM t_ai_teaching_model_document WHERE is_deleted = 0 and train_flag = 0 ORDER BY create_time DESC" no_train_document_result = await find_by_sql(no_train_document_sql, ()) if not no_train_document_result: @@ -49,4 +51,4 @@ async def train_document_task(): # execute_sql(update_sql) # 添加适当的等待时间,避免频繁查询 - await asyncio.sleep(60) # 每分钟查询一次 + await asyncio.sleep(60) # 每分钟查询一次 diff --git a/dsAiTeachingModel/utils/Database.py b/dsAiTeachingModel/utils/Database.py index 4ac15243..4010390d 100644 --- a/dsAiTeachingModel/utils/Database.py +++ b/dsAiTeachingModel/utils/Database.py @@ -17,7 +17,7 @@ async def create_pool(): password=POSTGRES_PASSWORD, database=POSTGRES_DATABASE, min_size=1, # 设置连接池最小连接数 - max_size=100 # 设置连接池最大连接数 + max_size=10 # 设置连接池最大连接数 ) async def get_connection():