refactor(rpa): 重构 scripts/rpa 目录结构与命名
按 common/connectors/inventory/receipt 分层并重命名 - common/: rpa_common, rpa_heartbeat, download_artifact_fallback, new_rpa_worker_secret - connectors/dsv|crane/: 登录网站连接器,库存与收料共用 - inventory/: inventory_rpa_worker, run_inventory_batch_trigger, start_inventory_worker, register_inventory_worker_tasks - receipt/: receipt_rpa_worker, receipt_crane/dbs_export, start_receipt_worker 保留裸 import + sys.path 引导;修正懒加载路径; 按范围命名 register_rpa_background_tasks -> register_inventory_worker_tasks; 同步 backend 测试、start_local.ps1、.env 注释、docs 与 README 路径。
This commit is contained in:
1 parent
09deada712
commit
f3050164d0
40 files changed
+384
-172
No files matched your search
@@ -0,0 +1,58 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
在当前 PowerShell 进程树启动独立货代收料 RPA Worker。
|
||||
|
||||
.DESCRIPTION
|
||||
只设置 Process 级环境变量和 receipt 专用目录;可与库存 Worker 并行运行,
|
||||
但二者不共享 trigger、drop、browser profile 或日志目录。
|
||||
#>
|
||||
param(
|
||||
[Parameter(Mandatory = $true)][ValidateSet('test', 'prod')][string]$Environment,
|
||||
[Parameter(Mandatory = $true)][string]$ApiBase,
|
||||
[Parameter(Mandatory = $true)][string]$WorkerRoot,
|
||||
[Parameter(Mandatory = $true)][string]$SecretFile,
|
||||
[string]$PythonExe = 'python.exe',
|
||||
[switch]$Mock,
|
||||
[switch]$Headless
|
||||
)
|
||||
|
||||
$ErrorActionPreference = 'Stop'
|
||||
if (-not (Test-Path -LiteralPath $SecretFile -PathType Leaf)) { throw "Secret 文件不存在:$SecretFile" }
|
||||
$workerScript = Join-Path $WorkerRoot 'scripts\rpa\receipt\receipt_rpa_worker.py'
|
||||
if (-not (Test-Path -LiteralPath $workerScript -PathType Leaf)) { throw "Worker 不存在:$workerScript" }
|
||||
|
||||
function ConvertTo-PlainText {
|
||||
param([Parameter(Mandatory = $true)][System.Security.SecureString]$Value)
|
||||
$pointer = [Runtime.InteropServices.Marshal]::SecureStringToBSTR($Value)
|
||||
try { return [Runtime.InteropServices.Marshal]::PtrToStringBSTR($pointer) }
|
||||
finally { [Runtime.InteropServices.Marshal]::ZeroFreeBSTR($pointer) }
|
||||
}
|
||||
|
||||
$secret = Import-Clixml -LiteralPath $SecretFile
|
||||
foreach ($required in @('ToolApiKey', 'CredentialKey')) {
|
||||
if (-not ($secret.PSObject.Properties.Name -contains $required)) { throw "Secret 文件缺少字段:$required" }
|
||||
}
|
||||
$dataRoot = Join-Path $WorkerRoot 'data\freight_receipt_rpa'
|
||||
$processVars = [ordered]@{
|
||||
HXOPS_API_BASE = $ApiBase
|
||||
SHIPPING_NOTICE_TOOL_API_KEY = ConvertTo-PlainText $secret.ToolApiKey
|
||||
SHIPPING_NOTICE_RPA_CREDENTIAL_KEY = ConvertTo-PlainText $secret.CredentialKey
|
||||
SHIPPING_NOTICE_RPA_WORKER_ENVIRONMENT = $Environment
|
||||
SHIPPING_NOTICE_RPA_WORKER_MOCK = $(if ($Mock) { 'true' } else { 'false' })
|
||||
SHIPPING_NOTICE_RPA_WORKER_HEADLESS = $(if ($Headless) { 'true' } else { 'false' })
|
||||
SHIPPING_NOTICE_RPA_WORKER_BROWSER_CHANNEL = 'msedge'
|
||||
SHIPPING_NOTICE_RPA_WORKER_POLL_SECONDS = '3'
|
||||
SHIPPING_NOTICE_RPA_SHARED_RECEIPT_TRIGGER_DIR = Join-Path $dataRoot 'receipt_triggers'
|
||||
SHIPPING_NOTICE_RPA_SHARED_RECEIPT_DROP_DIR = Join-Path $dataRoot 'receipt_drop'
|
||||
# 浏览器 Profile 目录复用既有标准变量(与库存 RPA Worker 一致),不另设 RECEIPT_* 冗余变量。
|
||||
SHIPPING_NOTICE_RPA_WORKER_BROWSER_PROFILE_DIR = Join-Path $WorkerRoot 'data\shipping_notice\freight_rpa\browser_profile'
|
||||
}
|
||||
foreach ($entry in $processVars.GetEnumerator()) { [Environment]::SetEnvironmentVariable($entry.Key, [string]$entry.Value, 'Process') }
|
||||
try {
|
||||
Write-Host "Starting receipt RPA Worker: environment=$Environment root=$WorkerRoot"
|
||||
& $PythonExe $workerScript
|
||||
exit $LASTEXITCODE
|
||||
}
|
||||
finally {
|
||||
foreach ($entry in $processVars.GetEnumerator()) { [Environment]::SetEnvironmentVariable($entry.Key, $null, 'Process') }
|
||||
}
|
||||
Reference in new issue
Block a user