fix(flow): 取消不再算失败——统一退出码 2 并在队列里显示「已取消」

- pipeline.run() 明确返回退出码:0 正常(含无需变更),2 用户取消;
  main.py 据此 sys.exit,媒体整理被取消时也能传到上层
- media-archive 的取消(选分类按 q、确认按 n)同样返回 2
- preview_and_confirm 遇到 EOF(没有 TTY/管道调用)按取消处理,
  不再抛 Traceback 崩掉
- 队列 worker 把退出码 2 显示为「⏭ 已取消(未改动任何文件)」,
  汇总区分 成功 / 取消 / 失败
This commit is contained in:
ali
2026-11-19 18:35:54 +08:00
parent 9091c67b25
commit 0819f784eb
4 changed files with 27 additions and 7 deletions
+11 -3
View File
@@ -184,6 +184,7 @@ function Invoke-Worker {
$done = 0
$failed = 0
$cancelled = 0
while ($true) {
$item = Take-QueueItem
@@ -206,6 +207,12 @@ function Invoke-Worker {
Write-Host (" ✅ 完成,用时 {0}s" -f $cost) -ForegroundColor Green
Write-WorkerLog ("完成 {0}({1}s)" -f $item.path, $cost)
}
elseif ($code -eq 2) {
# 退出码 2 约定为「用户主动取消」,不算失败
$cancelled++
Write-Host (" ⏭ 已取消(未改动任何文件),用时 {0}s" -f $cost) -ForegroundColor DarkYellow
Write-WorkerLog ("已取消 {0}" -f $item.path)
}
else {
$failed++
Write-Host (" ⚠️ 失败(退出码 {0}),用时 {1}s" -f $code, $cost) -ForegroundColor Red
@@ -214,11 +221,12 @@ function Invoke-Worker {
Write-Host ''
}
Write-Host ('📊 本次共处理 {0} 项:成功 {1},失败 {2}' -f ($done + $failed), $done, $failed) -ForegroundColor Cyan
$total = $done + $cancelled + $failed
Write-Host ('📊 本次共处理 {0} 项:成功 {1},取消 {2},失败 {3}' -f $total, $done, $cancelled, $failed) -ForegroundColor Cyan
Write-Host ' 队列已空,窗口即将关闭(详细记录见 worker.log)' -ForegroundColor DarkGray
Write-WorkerLog ("worker 退出:成功 {0},失败 {1}" -f $done, $failed)
Write-WorkerLog ("worker 退出:成功 {0},取消 {1},失败 {2}" -f $done, $cancelled, $failed)
$workerLock.Close()
if (($done + $failed) -gt 0) { Start-Sleep -Seconds 2 } # 留两秒给汇总留在屏幕上
if ($total -gt 0) { Start-Sleep -Seconds 2 } # 留两秒给汇总留在屏幕上
return 0
}