fix: 修复任务队列快照中已完成数一直为0的问题
部署到群晖 / deploy (push) Failing after 30s

切换频道前先等待所有 worker 下载完成,再拍快照,
避免快照时任务还在队列中导致 completed_files 始终为 0。

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
yuming
2026-04-29 21:59:38 +08:00
parent bc926bd972
commit eee81b5b0b
+13 -5
View File
@@ -705,6 +705,14 @@ async def download_chat_task(
update_task_progress(estimated_total=actual_total, is_checking=False)
async def _wait_node_finish(node: TaskNode):
"""等待单个频道的所有下载任务完成(含重试中的任务)"""
while True:
if node.need_check and node.finish_task >= node.total_task:
break
await asyncio.sleep(0.5)
async def download_all_chat(client: pyrogram.Client):
"""Download All chat"""
# Use list() to avoid "dictionary changed size during iteration" error
@@ -716,11 +724,11 @@ async def download_all_chat(client: pyrogram.Client):
logger.warning(f"Download {key} error: {e}")
finally:
value.need_check = True
# 所有频道串行跑完后,补一次最后频道的快照;否则末尾那个频道永远只留在 _task_progress
# 里、不会进 _completed_chats,前端会一直显示「🚀 下载中」
snapshot_current_chat()
# snapshot 只是复制、不会清空 _task_progress,必须 reset 一下,否则前端 h-skip 会把
# 最后频道的 skipped_files 同时计入 completed_chats 汇总和当前值,造成双计
# 等当前频道所有下载任务跑完,再拍快照;否则 completed_files 还是 0
await _wait_node_finish(value.node)
snapshot_current_chat()
reset_task_progress()
# 所有频道都已在循环内快照并重置,此处仅确保最终状态干净
reset_task_progress()