feat(shipping-notice): 收料RPA接入调拨全链路并统一Worker触发目录消费
- 新增 common/trigger_consumer 领取/归档原语,库存与收料 Worker 统一四态目录契约,README 载明契约 - 触发先落单元行再原子写 trigger;假触发器委托真实服务;触发目录不可用单元标 failed - 回调终态桥接推进调拨来源任务,有推进即 commit 保证持久 - 预检接真实异动文件仓库与 parse_movement_rows,行合成 sheet/row_no 溯源 - 等待回调来源任务超时回收挂每轮排程领取,绝不自动重试 - 三环境补收料共享目录 env,值对齐 §1.9.3 挂载约定
This commit is contained in:
1 parent
80d78130f8
commit
65f751daf4
23 files changed
+607
-91
No files matched your search
@@ -90,6 +90,7 @@ import worker_disk_cleanup # noqa: E402
|
||||
from download_artifact_fallback import ( # noqa: E402
|
||||
wait_for_new_download_file as _wait_for_new_download_file,
|
||||
)
|
||||
from trigger_consumer import claim_trigger # noqa: E402
|
||||
|
||||
# 测试与 smoke 向后兼容 re-export
|
||||
_maybe_auto_login_dsv = dsv_session.maybe_auto_login_dsv
|
||||
@@ -1550,7 +1551,7 @@ def _handle_inventory_batch_trigger(trigger_path: Path, drop_dir: Path, processe
|
||||
run_no = str(body.get("batch_run_no") or body.get("run_no") or trigger_path.stem).strip()
|
||||
task_no = str(body.get("task_no") or "").strip()
|
||||
sources = body.get("inventory_sources") or []
|
||||
failed_dir = trigger_path.parent / "failed"
|
||||
failed_dir = processed_dir.parent / "failed"
|
||||
# [DEBUG-TIMING] 批处理整体耗时基线:从进入 handler 到回调完成。
|
||||
batch_started_at = time.monotonic()
|
||||
print(f"[inventory-batch-timing] handler start run={run_no}")
|
||||
@@ -1862,7 +1863,7 @@ def _handle_inventory_trigger(trigger_path: Path, drop_dir: Path, processed_dir:
|
||||
_handle_inventory_batch_trigger(trigger_path, drop_dir, processed_dir)
|
||||
return
|
||||
task_no = str(body.get("task_no") or "").strip()
|
||||
failed_dir = trigger_path.parent / "failed"
|
||||
failed_dir = processed_dir.parent / "failed"
|
||||
if not task_no:
|
||||
print(f"[skip] invalid inventory trigger: {trigger_path.name}")
|
||||
trigger_path.unlink(missing_ok=True)
|
||||
@@ -2598,7 +2599,7 @@ def _handle_upload_trigger(trigger_path: Path, processed_dir: Path) -> None:
|
||||
file_path = str(body.get("file_path") or "").strip()
|
||||
attempt_id = body.get("attempt_id")
|
||||
callback_id = str(body.get("callback_id") or "").strip()
|
||||
failed_dir = trigger_path.parent / "failed"
|
||||
failed_dir = processed_dir.parent / "failed"
|
||||
if not task_no:
|
||||
trigger_path.unlink(missing_ok=True)
|
||||
return
|
||||
@@ -2686,11 +2687,16 @@ def _scan_triggers(trigger_dir: Path, handler, extra_args: tuple = ()) -> None:
|
||||
for path in sorted(trigger_dir.glob("*.json")):
|
||||
if not path.is_file():
|
||||
continue
|
||||
# 统一四态契约:先原子领取到 processing/ 再处理;被抢走/已消失则跳过,
|
||||
# 防止 Worker 重启或多实例部署时同一批 trigger 被重复导出、重复回调。
|
||||
claimed = claim_trigger(path)
|
||||
if claimed is None:
|
||||
continue
|
||||
rpa_heartbeat.set_worker_runtime_status("busy")
|
||||
try:
|
||||
handler(path, *extra_args)
|
||||
handler(claimed, *extra_args)
|
||||
except Exception as exc:
|
||||
print(f"[error] {path.name}: {exc}", file=sys.stderr)
|
||||
print(f"[error] {claimed.name}: {exc}", file=sys.stderr)
|
||||
finally:
|
||||
rpa_heartbeat.set_worker_runtime_status("idle")
|
||||
|
||||
|
||||
Reference in new issue
Block a user