refactor(shipping-inventory): 统一库存准备事实来源与门禁状态
This commit is contained in:
1 parent
761a06e21a
commit
eb55f407ae
62 files changed
+4242
-1471
No files matched your search
@@ -458,18 +458,29 @@ def _report_callback_failure(trigger_path: Path, failed_dir: Path, exc: Exceptio
|
||||
|
||||
def _close_batch_browser_resources(context: Any, playwright: Any, runtime_profile_dir: Path | None) -> None:
|
||||
"""在正常完成或 Ctrl+C 中断后依序释放批量 RPA 浏览器资源。"""
|
||||
# [DEBUG-TIMING] 逐阶段计时:浏览器关闭 / playwright 停止 / profile 清理各自耗时,
|
||||
# 用于定位「导出完成 → 回调」之间的静默段(export done 后到 _post_callback 前的耗时)。
|
||||
close_started_at = time.monotonic()
|
||||
try:
|
||||
if context is not None:
|
||||
context.close()
|
||||
except BaseException as exc:
|
||||
print(f"[browser] context close interrupted: {exc}", file=sys.stderr)
|
||||
else:
|
||||
print(f"[browser-cleanup] context.close elapsedMs={int((time.monotonic() - close_started_at) * 1000)}")
|
||||
stop_started_at = time.monotonic()
|
||||
try:
|
||||
if playwright is not None:
|
||||
playwright.stop()
|
||||
except BaseException as exc:
|
||||
print(f"[browser] playwright stop interrupted: {exc}", file=sys.stderr)
|
||||
else:
|
||||
print(f"[browser-cleanup] playwright.stop elapsedMs={int((time.monotonic() - stop_started_at) * 1000)}")
|
||||
cleanup_started_at = time.monotonic()
|
||||
if runtime_profile_dir is not None and _should_cleanup_browser_profile(runtime_profile_dir):
|
||||
shutil.rmtree(runtime_profile_dir, ignore_errors=True)
|
||||
print(f"[browser-cleanup] profile rmtree elapsedMs={int((time.monotonic() - cleanup_started_at) * 1000)} dir={runtime_profile_dir.name!r}")
|
||||
print(f"[browser-cleanup] total_cleanup elapsedMs={int((time.monotonic() - close_started_at) * 1000)}")
|
||||
|
||||
|
||||
_INVENTORY_V2_REQUIRED_FIELDS = (
|
||||
@@ -1123,6 +1134,9 @@ def _handle_inventory_batch_trigger(trigger_path: Path, drop_dir: Path, processe
|
||||
task_no = str(body.get("task_no") or "").strip()
|
||||
sources = body.get("inventory_sources") or []
|
||||
failed_dir = trigger_path.parent / "failed"
|
||||
# [DEBUG-TIMING] 批处理整体耗时基线:从进入 handler 到回调完成。
|
||||
batch_started_at = time.monotonic()
|
||||
print(f"[inventory-batch-timing] handler start run={run_no}")
|
||||
if not isinstance(sources, list) or not sources:
|
||||
trigger_path.unlink(missing_ok=True)
|
||||
return
|
||||
@@ -1391,6 +1405,9 @@ def _handle_inventory_batch_trigger(trigger_path: Path, drop_dir: Path, processe
|
||||
"schedule_run_id": body.get("schedule_run_id"),
|
||||
"results": results,
|
||||
}
|
||||
# [DEBUG-TIMING] 到达回调前打点:若此前有明显的静默段(浏览器清理),此处能看到
|
||||
# handler 启动到回调前的累计耗时,配合 _close_batch_browser_resources 的逐段计时即可定位。
|
||||
print(f"[inventory-batch-timing] before callback run={run_no} totalElapsedMs={int((time.monotonic() - batch_started_at) * 1000)}")
|
||||
_post_callback(callback_path, callback_payload)
|
||||
_move_trigger(trigger_path, processed_dir, "processed")
|
||||
print(
|
||||
|
||||
Reference in new issue
Block a user