feat(in-transit-transfer): 落地证据流重解析并纳入货代与排程配套改动
外部单号进入异动档自然键,圈档按 T-2 成熟封顶,当前归档可单独重解析。同批带上 Crane 禁整页刷新、ODM 白名单降级、排程抽屉与执行记录日期窗,以及 YAML 库存源下线。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
911afa0f73
commit
4c2a7e2a23
145 files changed
+11695
-4214
No files matched your search
@@ -5,10 +5,10 @@ scripts/freight_rpa/outbound/outbound_crane_export.py
|
||||
依赖:crane_report_export、crane_session。
|
||||
逻辑:outbound_rpa_worker 按 connector_type=crane 调用;写入 __download_dir 供共享
|
||||
driver 在 Playwright 未返回 Download 时做目录兜底。
|
||||
页面名/hash 与 Task 6 占位一致:report_name=Outbound Details、
|
||||
hash=#/outbound-details-query(入站对称占位;禁止误用 Inbound Details)。
|
||||
来源:Task 6 Crane 校验器 + 设计 D7 固定页;货代实名页尚未用截图/环境确认,
|
||||
若门户 hash 不同,只改本文件常量并同步管理端校验。
|
||||
页面名/hash 已实测确认(2026-10-20):report_name=Outbound Details、
|
||||
hash=#/outbound-details-query 与门户 Queries 菜单实名一致(导航侧由
|
||||
crane_navigation 按 entry_url 推导卡片/菜单;门户刷新即掉登录,登录态下禁止整页导航)。
|
||||
若门户调整 hash,只改本文件常量并同步管理端校验。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
@@ -7,6 +7,8 @@ scripts/freight_rpa/outbound/outbound_rpa_worker.py
|
||||
逻辑:排程写入 outbound trigger → 本进程领取并按 connector/profile 分组串行导出 →
|
||||
导出重试只覆盖落盘/校验(对齐库存/入站);有表头无明细 → empty/no_outbound_data;
|
||||
成功后先轻量 batch-progress 再 ready 归档回调;ready 超时不得重新下载。
|
||||
批级失败(如 launch_persistent_context 浏览器已关)须对本组未终态单元逐笔
|
||||
failed 回调——与 inbound/onhand 同契约,禁止只归档 trigger 不收口单元。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
@@ -459,6 +461,34 @@ def _report_failure(unit: dict[str, Any], exc: Exception) -> None:
|
||||
_post_callback({'schema_version': 'freight_rpa.outbound.v1', 'callback_id': unit.get('callback_id'), 'status': 'failed', 'error_code': 'RPA.OUTBOUND_EXPORT_FAILED', 'error_message': str(exc)[:2000]})
|
||||
|
||||
|
||||
def _report_group_open_failure(group: list[dict[str, Any]], exc: Exception) -> None:
|
||||
"""批级浏览器打开/组级异常时,为组内全部单元补发 failed 回调。
|
||||
|
||||
用途:``_open_browser`` 在进入单元循环前失败时,原先只把 trigger 归档到 failed/
|
||||
而不回调 → 后端单元永久 awaiting_rpa、调拨来源投影永久 fetching 且批量重试锁死
|
||||
(须等 FREIGHT_RPA_OUTBOUND_TIMEOUT_SECONDS 孤儿回收)。与 inbound Worker
|
||||
``_report_group_open_failure`` 同契约。本函数 best-effort 逐笔 ``_report_failure``,
|
||||
单笔回调失败只打日志不中断其余。
|
||||
|
||||
Args:
|
||||
group: 同一 connector/profile/login 下尚未进入终态回调的单元列表。
|
||||
exc: 批级异常(通常为 Playwright TargetClosed / launch_persistent_context)。
|
||||
"""
|
||||
print(
|
||||
f'[outbound-batch] open/group failed; reporting {len(group)} unit failure callback(s): '
|
||||
f'{str(exc)[:200]}',
|
||||
file=_sys.stderr,
|
||||
)
|
||||
for unit in group:
|
||||
try:
|
||||
_report_failure(unit, exc)
|
||||
except Exception as callback_exc:
|
||||
print(
|
||||
f'[outbound-unit] failed callback failed source={unit.get("source_code")}: {callback_exc}',
|
||||
file=_sys.stderr,
|
||||
)
|
||||
|
||||
|
||||
def _report_empty(unit: dict[str, Any], exc: NoOutboundDataError) -> None:
|
||||
"""无业务明细的合法结果:回调 empty + no_outbound_data(后端 finalize 计 skipped)。"""
|
||||
print(f'[outbound-unit] empty source={unit.get("source_code")} callback={unit.get("callback_id")} message={str(exc)[:200]}')
|
||||
@@ -619,6 +649,8 @@ def _process_units(body: dict[str, Any], drop_dir: Path) -> None:
|
||||
mock = env('FREIGHT_RPA_WORKER_MOCK', 'false').lower() == 'true'
|
||||
reuse_session = _session_reuse_enabled()
|
||||
resources = (None, None, None, None)
|
||||
# [STEP] 已终态回调的 callback_id:批级异常时只给剩余单元补 failed,避免双重终态。
|
||||
reported_callback_ids: set[str] = set()
|
||||
try:
|
||||
if not mock:
|
||||
resources = _open_browser(
|
||||
@@ -690,6 +722,7 @@ def _process_units(body: dict[str, Any], drop_dir: Path) -> None:
|
||||
f'[outbound-unit] empty callback failed source={unit.get("source_code")}: {callback_exc}',
|
||||
file=_sys.stderr,
|
||||
)
|
||||
reported_callback_ids.add(str(unit.get('callback_id') or ''))
|
||||
progress_counts['empty'] += 1
|
||||
_emit_batch_progress(body, progress_counts)
|
||||
continue
|
||||
@@ -701,6 +734,7 @@ def _process_units(body: dict[str, Any], drop_dir: Path) -> None:
|
||||
f'[outbound-unit] failed callback failed source={unit.get("source_code")}: {callback_exc}',
|
||||
file=_sys.stderr,
|
||||
)
|
||||
reported_callback_ids.add(str(unit.get('callback_id') or ''))
|
||||
progress_counts['failed'] += 1
|
||||
_emit_batch_progress(body, progress_counts)
|
||||
continue
|
||||
@@ -722,6 +756,17 @@ def _process_units(body: dict[str, Any], drop_dir: Path) -> None:
|
||||
f'file={output.name}: {callback_exc}',
|
||||
file=_sys.stderr,
|
||||
)
|
||||
reported_callback_ids.add(str(unit.get('callback_id') or ''))
|
||||
except Exception as exc:
|
||||
# [STEP] 批级失败(浏览器未开 / 凭据上下文崩 / 未捕获逃逸):剩余单元补 failed,
|
||||
# 与 inbound/onhand 同契约——禁止只归档 trigger 导致 awaiting_rpa 永挂。
|
||||
remaining = [
|
||||
unit for unit in group
|
||||
if str(unit.get('callback_id') or '') not in reported_callback_ids
|
||||
]
|
||||
if remaining:
|
||||
_report_group_open_failure(remaining, exc)
|
||||
raise
|
||||
finally:
|
||||
playwright, context, _page, profile_dir = resources
|
||||
if context is not None:
|
||||
|
||||
Reference in new issue
Block a user