@@ -69,7 +69,7 @@ def _format_run_summary(raw_run: Dict[str, Any]) -> Dict[str, Any]:
6969
7070# _progress 的初始结构,每次 start_sync 前重置为此形态
7171_PROGRESS_INIT : Dict [str , Any ] = {
72- "status" : "idle" , # idle / syncing / confirm_needed / done / error
72+ "status" : "idle" , # idle / syncing / confirm_needed / postprocessing / done / error
7373 "current_product" : "" , # 最近完成的产品名
7474 "completed" : 0 , # 已完成产品数
7575 "total" : 0 , # 本次同步产品总数
@@ -79,6 +79,7 @@ def _format_run_summary(raw_run: Dict[str, Any]) -> Dict[str, Any]:
7979 "products" : [], # 已完成产品列表 [{name, status, elapsed_seconds, files_count}]
8080 "all_products" : [], # 全部产品名列表(由 progress_callback 初始化调用时传入)
8181 "estimate" : None , # EstimateResult 的 dict 表示(confirm_needed 时填充)
82+ "postprocess_detail" : "" , # 后处理阶段描述(用户可读)
8283}
8384
8485
@@ -432,8 +433,8 @@ def start_sync(self, retry_failed: bool = False) -> Dict[str, Any]:
432433 # 检查 worker 线程是否仍在运行(cancel 后 status 变 error,但线程可能未退出)
433434 if hasattr (self , "_sync_thread" ) and self ._sync_thread and self ._sync_thread .is_alive ():
434435 return {"started" : False , "message" : "同步正在进行中,请等待完成后再试。" }
435- # confirm_needed 状态表示同步已在进行中(等待用户确认) ,也需拦截
436- if self ._progress .get ("status" ) in ("syncing" , "confirm_needed" ):
436+ # confirm_needed/postprocessing 状态表示同步已在进行中,也需拦截
437+ if self ._progress .get ("status" ) in ("syncing" , "confirm_needed" , "postprocessing" ):
437438 return {"started" : False , "message" : "同步正在进行中,请等待完成后再试。" }
438439
439440 # retry_failed 分支:从上次 run_summary 读取失败产品名
@@ -552,7 +553,7 @@ def open_data_dir(self) -> Dict[str, Any]:
552553 def start_health_check (self ) -> Dict [str , Any ]:
553554 """启动后台健康检查线程。同步中(含等待确认)拒绝,重复启动拒绝。"""
554555 with self ._lock :
555- if self ._progress .get ("status" ) in ("syncing" , "confirm_needed" ):
556+ if self ._progress .get ("status" ) in ("syncing" , "confirm_needed" , "postprocessing" ):
556557 return {"ok" : False , "error" : "同步进行中,请稍后再试" }
557558 if self ._health_progress ["checking" ]:
558559 return {"ok" : False , "error" : "检查已在进行中" }
@@ -606,9 +607,9 @@ def get_health_result(self) -> Dict[str, Any]:
606607 return self ._health_progress .get ("result" )
607608
608609 def repair_health_issues (self ) -> Dict [str , Any ]:
609- """修复可修复的数据问题。同步中(含等待确认)拒绝。"""
610+ """修复可修复的数据问题。同步中(含等待确认/后处理 )拒绝。"""
610611 with self ._lock :
611- if self ._progress .get ("status" ) in ("syncing" , "confirm_needed" ):
612+ if self ._progress .get ("status" ) in ("syncing" , "confirm_needed" , "postprocessing" ):
612613 return {"ok" : False , "error" : "同步进行中,请稍后修复" }
613614 result = self ._health_progress .get ("result" )
614615 if not result or not result .get ("ok" ):
@@ -866,6 +867,12 @@ def progress_callback(product_name: str, completed: int, total: int, *,
866867 if status == "init" :
867868 self ._progress ["total" ] = total
868869 return
870+ # 后处理阶段:更新顶层 status 和 elapsed,供前端检测
871+ if status == "postprocessing" :
872+ self ._progress ["status" ] = "postprocessing"
873+ self ._progress ["elapsed_seconds" ] = round (time .time () - t_start , 1 )
874+ self ._progress ["postprocess_detail" ] = _kwargs .get ("postprocess_detail" , "" )
875+ return
869876 # 计算本产品同步的文件数(新建 + 更新)
870877 files_count = (stats .created_files + stats .updated_files ) if stats else 0
871878 # 追加到已完成产品列表,包含 error 字段供前端展示失败原因
0 commit comments