优化脚本生成卡住问题

This commit is contained in:
Azmat@qq.com
2026-09-02 15:12:50 +08:00
parent c9522eea08
commit 22ed2833ad
5 changed files with 205 additions and 1 deletions
+7 -1
View File
@@ -1670,7 +1670,7 @@ def stream_script_agent(
):
"""生成 SSE 帧字符串的同步生成器,供 StreamingHttpResponse 包裹。
target_index 非空 = 精准只改第 N 镜(读全脚本上下文,后端强制保留其余镜原样)。"""
from apps.ai.services import create_ai_task, stream_routed_text_request
from apps.ai.services import create_ai_task, reap_stale_script_tasks, stream_routed_text_request
# 极速成片与专业创作都只产出口播。历史项目、模板或请求里的短剧/Vlog
# 仅作兼容读取,绝不能重新进入实际生成链路。
@@ -1724,6 +1724,12 @@ def stream_script_agent(
yield _sse({"type": "tool", "id": "analyze", "status": "done"})
task_type = AITask.Type.SCRIPT_OPTIMIZATION if mode == "revise" else AITask.Type.SCRIPT_GENERATION
# 顺手回收本团队被进程重启丢下的僵尸脚本任务(没有定时任务,沿用本项目「提交时顺手清」的做法):
# 存量卡「进行中」的行会在下一次生成时自愈,冻住的预扣积分也一并退回。
try:
reap_stale_script_tasks(team=project.team)
except Exception: # noqa: BLE001 — 回收失败不该挡住本次生成
logger.warning("reap stale script tasks failed", exc_info=True)
try:
task = create_ai_task(
project=project,