Skip to content

armgit / peach

Public Imported from GitHub
0

Peach: Local-first video metadata scraper and media manager.

fix(scraping): 取消全部检查时不再等排队的来源

longmeidao7dfc13dbe07b
diff --git a/frontend/src/react/scraping/scraping.ts b/frontend/src/react/scraping/scraping.ts
index 0bcd83044..d4cee4ebd 100644
--- a/frontend/src/react/scraping/scraping.ts
+++ b/frontend/src/react/scraping/scraping.ts
@@ -1,7 +1,7 @@
/* 来源和凭证页的数据契约与折算。几条端点在 `frontend/src` 里都只在这里声明一次
* (`tests/test_frontend_build.py` 盯着)。
*
- * 来源配置、封面任务、amane 桥和自定义来源各自缓存;后台任务按自己的节律读取状态,
+ * 来源配置、连接检查、封面任务、amane 桥和自定义来源各自缓存;后台任务按自己的节律读取状态,
* 不重取正在编辑的来源配置。 */
import { apiGet } from '../../api';
import { queryClient } from '../query';
diff --git a/src/peach/source_preflight.py b/src/peach/source_preflight.py
index df891f69b..2a4f85fad 100644
--- a/src/peach/source_preflight.py
+++ b/src/peach/source_preflight.py
@@ -50,12 +50,16 @@ def check_sources(secrets_root: Path, sources: list[str] | None = None, *,
started = time.monotonic()
finished: dict[str, dict] = {}
- with ThreadPoolExecutor(max_workers=4, thread_name_prefix="source-check") as pool:
+ pool = ThreadPoolExecutor(max_workers=4, thread_name_prefix="source-check")
+ try:
futures = {pool.submit(check, source): source for source in selected}
for future in as_completed(futures):
row = finished[futures[future]] = future.result()
if on_result is not None:
on_result(row)
+ finally:
+ # 任务中心取消时 `on_result` 抛出:只等已在检查的来源,排队的不再开始。
+ pool.shutdown(wait=True, cancel_futures=True)
results = [finished[source] for source in selected]
return {"ok": all(target["ok"] or target.get("reason") == "needs_code"
for source in results for target in source["results"]),