Merge branch 'hugo-auto-transfer' into dev

This commit is contained in:
hugo committed 2026-10-08 11:07:47 +08:00
commit ffbcb93b2e
2 files changed
+23 -6

No files matched your search

@@ -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,