tingwu_new
All checks were successful
Deploy to Server / deploy (push) Successful in 17s

This commit is contained in:
jeremygan2021
2026-03-11 22:35:37 +08:00
parent c32522857e
commit 5a87105ec9
2 changed files with 49 additions and 8 deletions

View File

@@ -225,9 +225,34 @@ class TranscriptionTaskViewSet(viewsets.ModelViewSet):
eval.save()
evaluations_to_process.append(eval)
# 执行评估
for eval_obj in evaluations_to_process:
service.evaluate_task(eval_obj)
# 执行评估 (改为异步并发执行)
# 提取ID列表避免传递模型对象导致可能的线程问题
eval_ids = [e.id for e in evaluations_to_process]
if eval_ids:
import threading
from concurrent.futures import ThreadPoolExecutor
def run_evaluations_background(ids):
# 在后台线程中重新引入依赖
from .models import AIEvaluation
from .bailian_service import BailianService
# 为该线程创建独立的服务实例
local_service = BailianService()
# 获取最新的对象
target_evals = AIEvaluation.objects.filter(id__in=ids)
# 使用线程池并发执行
# max_workers=4 可以同时处理4个评估请求
with ThreadPoolExecutor(max_workers=4) as executor:
executor.map(local_service.evaluate_task, target_evals)
# 启动后台线程,不阻塞当前 HTTP 请求
thread = threading.Thread(target=run_evaluations_background, args=(eval_ids,))
thread.daemon = True # 设置为守护线程
thread.start()
# 返回该任务的所有评估结果
all_evals = AIEvaluation.objects.filter(task=task)