feat: 任务断点续跑/暂停中断/LLM 过滤优化与调度容错
调度与状态机: - 修复 PAUSED 任务被拾起后复活执行(点击暂停反而开始任务):next_queued_run 只取 QUEUED,execute_run 以 PAUSED 进入直接返回,暂停必须显式 resume - 重启恢复:启动时 recover_interrupted_runs 把遗留 RUNNING 置 QUEUED(保留产物) - 暂停信号 paused.flag:暂停接口写、继续/重试清除,OCR 逐帧检查秒级中断, 节点内被暂停保持 PAUSED 不误报 FAILED - 调度轮询容错:_loop 异常不杀死线程(曾致任务永久停留 QUEUED) subtitle-ocr 节点级断点: - ocr_partial.jsonl 逐帧存档,重启/暂停后只处理未处理帧,产物与一次跑完一致 - 进度日志携带窗口平均耗时与线程数;取消后抑制进度日志井喷 llm-filter 过滤质量与限流自适应: - 上下文净化:喂给 LLM 的是过滤后的字幕(规则层垃圾从上下文剔除) - 正则确定性过滤:裸网址域名、HTML/水印模式直接删除 - 429/5xx 指数退避重试;worker 限流错误 report_failure 内存临时降最大线程数 并缩容(无错误窗口回升),失败条目降并发后重试一轮 - 保留长文本保护(noise 不删 ≥min_keep_len 文本,LLM 判定不稳的必要兜底) 前端: - 工作流编排页支持选择工作流编辑(加载最新/历史版本)、版本历史面板、 新建/编辑双模式;管理后台编辑跳转 workflow.html?edit=<id> 工作流:ocr-subtitle v7(filter pool_max_workers=20、pool_fast_threshold=1)
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
"""一次性诊断:实测 SiliconFlow API 在不同并发下的 429 限流情况。
|
||||
|
||||
用于确定 llm_filter 的安全并发上限(run_011d01f19999 在 20/4 并发下均 429)。
|
||||
"""
|
||||
import json
|
||||
import os
|
||||
import threading
|
||||
import time
|
||||
import urllib.error
|
||||
import urllib.request
|
||||
from pathlib import Path
|
||||
|
||||
from dotenv import load_dotenv
|
||||
|
||||
load_dotenv(Path(".env"))
|
||||
|
||||
API_BASE = os.getenv("LLM_API_BASE", "https://api.siliconflow.cn/v1/chat/completions")
|
||||
API_KEY = os.getenv("LLM_API_KEY", "")
|
||||
MODEL = os.getenv("LLM_MODEL", "Qwen/Qwen3.6-35B-A3B")
|
||||
|
||||
|
||||
def one_call(idx: int) -> str:
|
||||
"""发送一次最小 LLM 请求,返回结果码:ok / 429 / 其他。"""
|
||||
body = {
|
||||
"model": MODEL,
|
||||
"messages": [
|
||||
{"role": "system", "content": "你是字幕质量过滤器。"},
|
||||
{"role": "user", "content": f"【目标】测试请求 {idx}"},
|
||||
],
|
||||
"enable_thinking": False,
|
||||
"max_tokens": 8,
|
||||
}
|
||||
req = urllib.request.Request(
|
||||
API_BASE,
|
||||
data=json.dumps(body).encode("utf-8"),
|
||||
headers={"Content-Type": "application/json", "Authorization": f"Bearer {API_KEY}"},
|
||||
method="POST",
|
||||
)
|
||||
try:
|
||||
with urllib.request.urlopen(req, timeout=30) as resp:
|
||||
resp.read()
|
||||
return "ok"
|
||||
except urllib.error.HTTPError as exc:
|
||||
# 429 时尝试读取响应体里的限流信息
|
||||
try:
|
||||
detail = exc.read().decode("utf-8")[:120]
|
||||
except Exception:
|
||||
detail = ""
|
||||
retry_after = exc.headers.get("Retry-After") if exc.headers else None
|
||||
return f"HTTP {exc.code} | Retry-After={retry_after} | {detail}"
|
||||
except Exception as exc: # noqa: BLE001
|
||||
return f"{type(exc).__name__}: {exc}"
|
||||
|
||||
|
||||
def probe(concurrency: int, total: int) -> list[str]:
|
||||
"""以给定并发发送 total 个请求,返回结果码列表。"""
|
||||
results: list[str] = []
|
||||
lock = threading.Lock()
|
||||
index = 0
|
||||
|
||||
def worker() -> None:
|
||||
nonlocal index
|
||||
while True:
|
||||
with lock:
|
||||
if index >= total:
|
||||
return
|
||||
i = index
|
||||
index += 1
|
||||
with lock:
|
||||
results.append(one_call(i))
|
||||
|
||||
threads = [threading.Thread(target=worker) for _ in range(concurrency)]
|
||||
for t in threads:
|
||||
t.start()
|
||||
for t in threads:
|
||||
t.join()
|
||||
return results
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
for conc in (1, 2, 4, 8):
|
||||
results = probe(conc, total=8)
|
||||
ok = sum(1 for r in results if r == "ok")
|
||||
other = [r for r in results if r != "ok"][:2]
|
||||
print(f"并发 {conc:2d}: 8 请求 -> ok {ok}/8 | 其余样例: {other}")
|
||||
time.sleep(2) # 组间休息,避免误伤
|
||||
Reference in New Issue
Block a user