From e8d9dba8a3541fb75444cca10a84dd83d4d70309 Mon Sep 17 00:00:00 2001 From: caohuipeng Date: Thu, 8 Oct 2026 11:06:25 +0800 Subject: [PATCH] =?UTF-8?q?fix(freight-rpa):=20=E4=B8=A4=E5=9F=9F=E8=B6=85?= =?UTF-8?q?=E6=97=B6=E6=94=BE=E5=AE=BD=E8=87=B3=201=20=E5=B0=8F=E6=97=B6?= =?UTF-8?q?=E5=B9=B6=E5=BC=BA=E5=88=B6=E6=94=B6=E6=96=99=E9=87=8D=E8=AF=95?= =?UTF-8?q?=E5=AE=8C=E6=95=B4=E9=87=8D=E5=AF=BC=E8=88=AA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 库存/收料超时 900s 放宽到 3600s:对账按笔间静默判活后,超时须覆盖最坏批次总时长,防健康在飞批次被误回收(RUN20261008003113B726 实测教训) - 收料 worker 重试尝试(attempt>1)强制完整重导航:对齐库存 AWSRTM 兜底,报表导出菜单缺失属瞬态故障,须回入口页重选菜单,绝不在错误页直接重试 - 凭据校验类失败(invalid/verification)为确定性失败,不进入重试 - 同步 test 环境超时配置 --- .env.test | 5 +++- .../freight_rpa/receipt/receipt_rpa_worker.py | 24 +++++++++++++++---- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/.env.test b/.env.test index 99e5e40a..1f124d1a 100644 --- a/.env.test +++ b/.env.test @@ -155,7 +155,10 @@ SHIPPING_NOTICE_LAYOUT_OCR_CROP_MARGIN_RATIO=0.03 SHIPPING_NOTICE_INVENTORY_SNAPSHOT_TTL_HOURS=24 # 共享目录逻辑标识(Ubuntu 后端与 Windows RPA 必须一致,用于哨兵校验与跨平台路径对齐) FREIGHT_RPA_SHARED_SCOPE_ID=hxops-rpa-test-data -FREIGHT_RPA_INVENTORY_TIMEOUT_SECONDS=900 +# 两域超时须覆盖最坏批次总时长(10 站串行 + 单站失败重试可达 30 分钟+), +# 否则每轮对账会把仍在飞的健康批次误回收(2026-10-08 RUN20261008003113B726 实测教训) +FREIGHT_RPA_INVENTORY_TIMEOUT_SECONDS=3600 +FREIGHT_RPA_RECEIPT_TIMEOUT_SECONDS=3600 FREIGHT_RPA_UPLOAD_MAX_ATTEMPTS=3 FREIGHT_RPA_UPLOAD_TIMEOUT_SECONDS=30 FREIGHT_RPA_WORKER_HEARTBEAT_TTL_SECONDS=90 diff --git a/scripts/freight_rpa/receipt/receipt_rpa_worker.py b/scripts/freight_rpa/receipt/receipt_rpa_worker.py index 23fa3cf1..efc97be9 100644 --- a/scripts/freight_rpa/receipt/receipt_rpa_worker.py +++ b/scripts/freight_rpa/receipt/receipt_rpa_worker.py @@ -490,17 +490,25 @@ def _export_unit_download( page: Any, context: Any, drop_dir: Path, + attempt: int = 1, ) -> tuple[Any, Any]: """ 导出单个收料单元的 Playwright Download;必要时干净页重试会话。 + Args: + attempt: 第几次尝试(1 起)。>1 时强制完整重导航(对齐库存 2026-09-20 AWSRTM + 兜底:报表页导出菜单缺失属瞬态故障,绝不在错误页上直接重试,须回入口页 + 重选菜单进报表),且 prepare 的导航/会话类异常一并走干净页安全网 + (凭据校验类 invalid/verification 为确定性失败,不重试)。 Returns: (download, page):download 为 Playwright Download;page 可能已切换为干净页。 """ unit['__download_dir'] = str(drop_dir) if connector == 'dbs': source = receipt_dbs_export.build_receipt_dsv_source(unit, entry_url=login_url) - previous_unit = group[index - 1] if index > 0 else None + # 重试尝试强制完整重导航:不携带前一单元上下文,prepare 从入口页重选菜单进报表。 + force_full_navigation = attempt > 1 + previous_unit = group[index - 1] if (index > 0 and not force_full_navigation) else None previous_source = ( receipt_dbs_export.build_receipt_dsv_source(previous_unit, entry_url=login_url) if previous_unit is not None else None @@ -509,14 +517,18 @@ def _export_unit_download( try: skip_navigation = bool( dsv_report_export.prepare_dsv_batch_export_step( - page, login_url, previous_source, source, index=index, + page, login_url, previous_source, source, + index=0 if force_full_navigation else index, ) ) except Exception as exc: - if not _is_login_session_error(exc): + # 安全网:登录/会话与导航类瞬态异常均新开干净页重跑完整准备; + # 仅凭据校验类(invalid/verification)确定性失败不重试(对齐库存)。 + message = str(exc).lower() + if any(token in message for token in ('invalid', 'verification')): raise print( - f'[receipt-batch] dbs session prepare failed for {unit.get("source_code")}, ' + f'[receipt-batch] dbs prepare failed for {unit.get("source_code")}, ' f'retry with clean page: {exc}', file=_sys.stderr, ) @@ -531,7 +543,8 @@ def _export_unit_download( ) return download, page - first_in_profile = index == 0 + # Crane 重试尝试同样强制完整重登导航(first_in_profile=True 走首源完整登录)。 + first_in_profile = index == 0 or attempt > 1 try: download = receipt_crane_export.export_receipt_report( page, unit, env=env, browser_timeout_ms=browser_timeout_ms(), @@ -643,6 +656,7 @@ def _process_units(body: dict[str, Any], drop_dir: Path) -> None: page=page, context=context, drop_dir=drop_dir, + attempt=attempt, ) output = _save_download( download, drop_dir, unit, batch_run_no=batch_run_no,