feat(shipping-notice): 收敛阶段能力投影并修复库存 RPA 运行链路
下发 preparation capabilities 并与右卡展示同源授权; 库存 RPA 运行态请求内 memo;取消会话 Profile 本地 TTL; 并为 shipping-worker 挂载共享盘。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
f773237226
commit
a6edc4fe61
16 files changed
+433
-179
No files matched your search
@@ -20,7 +20,6 @@ Optional:
|
||||
SHIPPING_NOTICE_RPA_WORKER_SAMPLE_INVENTORY=path/to/sample.xlsx
|
||||
SHIPPING_NOTICE_RPA_WORKER_BROWSER_PROFILE_DIR=data/shipping_notice/freight_rpa/browser_profile
|
||||
SHIPPING_NOTICE_RPA_WORKER_SESSION_REUSE=true
|
||||
SHIPPING_NOTICE_RPA_WORKER_SESSION_REUSE_TTL_HOURS=24
|
||||
# legacy alias: SHIPPING_NOTICE_RPA_WORKER_DSV_SESSION_REUSE
|
||||
SHIPPING_NOTICE_RPA_WORKER_HEADLESS=false
|
||||
SHIPPING_NOTICE_RPA_WORKER_BROWSER_CHANNEL=msedge
|
||||
@@ -879,21 +878,6 @@ def _dsv_session_reuse_enabled() -> bool:
|
||||
return _session_reuse_enabled()
|
||||
|
||||
|
||||
def _session_reuse_ttl_seconds() -> int:
|
||||
"""
|
||||
返回持久 Profile 最长保留秒数。
|
||||
|
||||
核心逻辑:读取 `SHIPPING_NOTICE_RPA_WORKER_SESSION_REUSE_TTL_HOURS`,默认 24 小时;
|
||||
下限 1 小时,避免误配成 0 导致每次都重建。
|
||||
"""
|
||||
raw = _env("SHIPPING_NOTICE_RPA_WORKER_SESSION_REUSE_TTL_HOURS", "24") or "24"
|
||||
try:
|
||||
hours = int(raw)
|
||||
except ValueError:
|
||||
hours = 24
|
||||
return max(1, hours) * 3600
|
||||
|
||||
|
||||
def _sanitize_profile_dir_segment(value: str) -> str:
|
||||
"""
|
||||
将 connector / RPA Profile 编码成可作目录名的安全片段。
|
||||
@@ -915,7 +899,7 @@ def _session_profile_dir(connector_type: str, profile_code: str = "") -> Path:
|
||||
|
||||
核心逻辑:目录形如 `{connector}__{profile_code}_session`,不同货代账号绝不共用;
|
||||
若仍存在历史 `dsv360_session` 且目标目录尚未创建、profile 为 default,则沿用旧目录
|
||||
以保留已有登录态,待 TTL 过期后自然重建到新命名。
|
||||
以保留已有登录态。本地不按时间强制清空;站点会话失效时由登录流程兜底重登。
|
||||
|
||||
Args:
|
||||
connector_type: Worker 连接器名(如 dsv360 / crane_footprint)。
|
||||
@@ -972,7 +956,6 @@ def _write_session_meta(
|
||||
"last_used_at": datetime.fromtimestamp(now, tz=UTC).isoformat(),
|
||||
"connector_type": connector_type,
|
||||
"profile_code": profile_code,
|
||||
"ttl_hours": max(1, _session_reuse_ttl_seconds() // 3600),
|
||||
}
|
||||
meta_path = profile_dir / _SESSION_META_FILENAME
|
||||
meta_path.write_text(json.dumps(payload, ensure_ascii=False, indent=2), encoding="utf-8")
|
||||
@@ -985,10 +968,10 @@ def _prepare_reusable_session_profile(
|
||||
profile_code: str,
|
||||
) -> Path:
|
||||
"""
|
||||
准备可复用 Profile 目录:超 TTL 则清空重建,否则刷新 last_used。
|
||||
准备可复用 Profile 目录:确保存在并刷新 last_used,不按本地时间强制过期。
|
||||
|
||||
核心逻辑:以 meta 的 `created_at_unix` 起算;无 meta 时用目录 mtime。超过
|
||||
`SESSION_REUSE_TTL_HOURS`(默认 24h)则整目录删除后重建,迫使重新登录。
|
||||
核心逻辑:目录长期保留 Cookie/登录态;是否免登由货代站点会话是否仍有效决定,
|
||||
失效时各 connector 的 ensure_session / 登录流程会自动重登。
|
||||
|
||||
Args:
|
||||
profile_dir: 目标持久目录。
|
||||
@@ -996,47 +979,21 @@ def _prepare_reusable_session_profile(
|
||||
profile_code: RPA Profile 编码,写入 meta。
|
||||
|
||||
Returns:
|
||||
Path: 已确保存在且未过期的 profile 目录。
|
||||
Path: 已确保存在的 profile 目录。
|
||||
"""
|
||||
ttl_seconds = _session_reuse_ttl_seconds()
|
||||
now = time.time()
|
||||
if profile_dir.exists():
|
||||
meta = _read_session_meta(profile_dir)
|
||||
created_at = meta.get("created_at_unix")
|
||||
try:
|
||||
created_ts = float(created_at) if created_at is not None else profile_dir.stat().st_mtime
|
||||
except (TypeError, ValueError, OSError):
|
||||
created_ts = now
|
||||
age_seconds = max(0.0, now - created_ts)
|
||||
if age_seconds >= ttl_seconds:
|
||||
print(
|
||||
"[browser] session_reuse expired "
|
||||
f"ageHours={age_seconds / 3600:.1f} ttlHours={ttl_seconds / 3600:.0f} "
|
||||
f"dir={profile_dir.name!r}; recreating"
|
||||
)
|
||||
shutil.rmtree(profile_dir, ignore_errors=True)
|
||||
profile_dir.mkdir(parents=True, exist_ok=True)
|
||||
_write_session_meta(
|
||||
profile_dir,
|
||||
connector_type=connector_type,
|
||||
profile_code=profile_code,
|
||||
created_at_unix=now,
|
||||
)
|
||||
return profile_dir
|
||||
profile_dir.mkdir(parents=True, exist_ok=True)
|
||||
_write_session_meta(
|
||||
profile_dir,
|
||||
connector_type=connector_type,
|
||||
profile_code=profile_code,
|
||||
created_at_unix=created_ts,
|
||||
)
|
||||
return profile_dir
|
||||
profile_dir.mkdir(parents=True, exist_ok=True)
|
||||
meta = _read_session_meta(profile_dir)
|
||||
created_at = meta.get("created_at_unix")
|
||||
try:
|
||||
created_ts = float(created_at) if created_at is not None else now
|
||||
except (TypeError, ValueError):
|
||||
created_ts = now
|
||||
_write_session_meta(
|
||||
profile_dir,
|
||||
connector_type=connector_type,
|
||||
profile_code=profile_code,
|
||||
created_at_unix=now,
|
||||
created_at_unix=created_ts,
|
||||
)
|
||||
return profile_dir
|
||||
|
||||
@@ -1086,8 +1043,8 @@ def _open_browser(
|
||||
打开用于库存 / 上传 RPA 的浏览器上下文。
|
||||
|
||||
核心逻辑:库存导出在 `reuse_session=True` 且 `SESSION_REUSE` 开启时,使用
|
||||
`{connector}__{profile_code}_session` 持久目录并按 TTL 失效重建;关闭复用或上传
|
||||
任务则创建 `run_*` 一次性目录。会话失效仍由各 connector 登录流程兜底。
|
||||
`{connector}__{profile_code}_session` 持久目录长期保留登录态;关闭复用或上传
|
||||
任务则创建 `run_*` 一次性目录。站点会话失效时由各 connector 登录流程兜底。
|
||||
|
||||
Args:
|
||||
download_dir: 当前任务下载目录,浏览器 downloads_path 指向此处。
|
||||
|
||||
@@ -8,7 +8,8 @@
|
||||
每个环境必须有独立 root、scope、共享目录、browser profile、日志和 DPAPI Secret 文件。
|
||||
DSV/Crane 登录地址、账号和密码来自 HXOPS trigger 的 credential_envelope,
|
||||
不从本机 Secret 文件读取。
|
||||
默认开启库存会话复用(SESSION_REUSE + 24h TTL);需要每次全新登录时传 -NoSessionReuse。
|
||||
默认开启库存会话复用(SESSION_REUSE,长期保留 Profile;站点会话失效才重登);
|
||||
需要每次全新登录时传 -NoSessionReuse。
|
||||
#>
|
||||
param(
|
||||
[Parameter(Mandatory = $true)]
|
||||
@@ -65,7 +66,7 @@ foreach ($required in @("ToolApiKey", "CredentialKey")) {
|
||||
}
|
||||
}
|
||||
|
||||
# 库存 Profile 默认按 connector+rpa_profile 复用,TTL 24h;-NoSessionReuse 可关闭。
|
||||
# 库存 Profile 默认按 connector+rpa_profile 长期复用;-NoSessionReuse 可关闭。
|
||||
$sessionReuse = if ($NoSessionReuse) { "false" } else { "true" }
|
||||
if ($ReuseSession -or $ReuseDsvSession) {
|
||||
$sessionReuse = "true"
|
||||
@@ -82,7 +83,6 @@ $processVars = [ordered]@{
|
||||
SHIPPING_NOTICE_RPA_WORKER_MOCK = $(if ($Mock) { "true" } else { "false" })
|
||||
SHIPPING_NOTICE_RPA_WORKER_HEADLESS = $(if ($Headless) { "true" } else { "false" })
|
||||
SHIPPING_NOTICE_RPA_WORKER_SESSION_REUSE = $sessionReuse
|
||||
SHIPPING_NOTICE_RPA_WORKER_SESSION_REUSE_TTL_HOURS = "24"
|
||||
SHIPPING_NOTICE_RPA_WORKER_BROWSER_CHANNEL = "msedge"
|
||||
SHIPPING_NOTICE_RPA_WORKER_POLL_SECONDS = "3"
|
||||
SHIPPING_NOTICE_RPA_SHARED_INVENTORY_TRIGGER_DIR = Join-Path $dataRoot "inventory_triggers"
|
||||
|
||||
Reference in new issue
Block a user