切换频道前先等待所有 worker 下载完成,再拍快照, 避免快照时任务还在队列中导致 completed_files 始终为 0。 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
+12
-4
@@ -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,前端会一直显示「🚀 下载中」
|
||||
# 等当前频道所有下载任务跑完,再拍快照;否则 completed_files 还是 0
|
||||
await _wait_node_finish(value.node)
|
||||
snapshot_current_chat()
|
||||
# snapshot 只是复制、不会清空 _task_progress,必须 reset 一下,否则前端 h-skip 会把
|
||||
# 最后频道的 skipped_files 同时计入 completed_chats 汇总和当前值,造成双计
|
||||
reset_task_progress()
|
||||
# 所有频道都已在循环内快照并重置,此处仅确保最终状态干净
|
||||
reset_task_progress()
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user