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:
hugo committed 2026-09-18 01:38:29 +08:00
1 parent 80d78130f8
commit 65f751daf4
23 files changed
+607 -91

No files matched your search

+12 -14
View File
@@ -32,6 +32,7 @@ if _RPA_ROOT is not None:
_sys.path.insert(0, _dir)
from rpa_common import browser_timeout_ms, click_text, env, select_or_fill # noqa: E402
from trigger_consumer import archive_trigger, claim_trigger # noqa: E402
import receipt_crane_export # noqa: E402
import receipt_dbs_export # noqa: E402
@@ -200,24 +201,22 @@ def _process_units(body: dict[str, Any], drop_dir: Path) -> None:
shutil.rmtree(profile_dir, ignore_errors=True)
def _claim_and_process(path: Path, drop_dir: Path, processed_dir: Path, failed_dir: Path) -> None:
"""原子领取一个 receipt trigger;成功归档 processed,callback 异常归档 failed。"""
claimed_dir = path.parent / 'processing'
claimed_dir.mkdir(parents=True, exist_ok=True)
claimed = claimed_dir / path.name
try:
path.replace(claimed)
except OSError:
def _claim_and_process(path: Path, drop_dir: Path) -> None:
"""原子领取一个 receipt trigger;成功归档 processed,异常归档 failed。
领取与归档统一走 common/trigger_consumer(四态目录契约),
本函数只保留收料批次处理与 SystemExit 兜底。
"""
claimed = claim_trigger(path)
if claimed is None:
return
try:
_process_units(json.loads(claimed.read_text(encoding='utf-8')), drop_dir)
processed_dir.mkdir(parents=True, exist_ok=True)
claimed.replace(processed_dir / claimed.name)
archive_trigger(claimed, 'processed')
except (Exception, SystemExit):
# SystemExit 也一并捕获:_require_dir 缺 env 会抛 SystemExit(非 Exception),
# 若不捕获会静默退出进程、trigger 卡死在 processing/,无法归档到 failed/。
failed_dir.mkdir(parents=True, exist_ok=True)
claimed.replace(failed_dir / claimed.name)
archive_trigger(claimed, 'failed')
raise
@@ -226,12 +225,11 @@ def main() -> None:
drop_dir = _require_dir('SHIPPING_NOTICE_RPA_SHARED_RECEIPT_DROP_DIR')
trigger_dir = _require_dir('SHIPPING_NOTICE_RPA_SHARED_RECEIPT_TRIGGER_DIR')
poll = max(1, int(env('SHIPPING_NOTICE_RPA_WORKER_POLL_SECONDS', '3') or '3'))
processed_dir, failed_dir = trigger_dir / 'processed', trigger_dir / 'failed'
print(f'[freight_receipt_rpa_worker] started trigger_dir={trigger_dir} drop_dir={drop_dir}')
while True:
for path in sorted(trigger_dir.glob('*.json')):
try:
_claim_and_process(path, drop_dir, processed_dir, failed_dir)
_claim_and_process(path, drop_dir)
except Exception as exc:
print(f'[receipt-trigger] failed {path.name}: {exc}')
time.sleep(poll)