fix: 重试网商银行远程导入连接 #832
@ -120,12 +120,6 @@ $auth = Start-CaiwuDeploymentAuth -Server $Server -SshUser $SshUser
|
||||
try {
|
||||
$target = "${SshUser}@${Server}"
|
||||
$remoteDirectory = [IO.Path]::GetDirectoryName($remoteFile).Replace('\', '/')
|
||||
& ssh @($auth.Options) $target ("install -d -m 700 '" + $remoteDirectory + "'")
|
||||
if ($LASTEXITCODE -ne 0) { throw '创建网商银行账单远程目录失败' }
|
||||
|
||||
& scp @($auth.Options) $bundleFile ("${target}:" + $remoteFile)
|
||||
if ($LASTEXITCODE -ne 0) { throw '上传网商银行账单批次失败' }
|
||||
|
||||
$dryRunFlag = if ($DryRun) { ' --dry-run' } else { '' }
|
||||
$command = @(
|
||||
'set -eu',
|
||||
@ -133,13 +127,35 @@ try {
|
||||
"'$remoteFile' --date='$Date'" + $dryRunFlag),
|
||||
("rm -f '" + $remoteFile + "'")
|
||||
) -join '; '
|
||||
$importOutput = (& ssh @($auth.Options) $target $command 2>&1 | Out-String)
|
||||
$importExit = $LASTEXITCODE
|
||||
if (-not [string]::IsNullOrWhiteSpace($importOutput)) {
|
||||
Write-Log ('导入输出:' + ($importOutput.Trim() -replace "`r?`n", ' | '))
|
||||
$attempts = 3
|
||||
$importCompleted = $false
|
||||
for ($attempt = 1; $attempt -le $attempts; $attempt++) {
|
||||
try {
|
||||
& ssh @($auth.Options) $target ("install -d -m 700 '" + $remoteDirectory + "'")
|
||||
if ($LASTEXITCODE -ne 0) { throw '创建远程目录失败' }
|
||||
|
||||
& scp @($auth.Options) $bundleFile ("${target}:" + $remoteFile)
|
||||
if ($LASTEXITCODE -ne 0) { throw '上传批次失败' }
|
||||
|
||||
$importOutput = (& ssh @($auth.Options) $target $command 2>&1 | Out-String)
|
||||
$importExit = $LASTEXITCODE
|
||||
if (-not [string]::IsNullOrWhiteSpace($importOutput)) {
|
||||
Write-Log ('导入输出:' + ($importOutput.Trim() -replace "`r?`n", ' | '))
|
||||
}
|
||||
if ($importExit -ne 0) { throw '受限批处理命令返回失败' }
|
||||
|
||||
$importCompleted = $true
|
||||
break
|
||||
} catch {
|
||||
if ($attempt -lt $attempts) {
|
||||
Write-Log ("远程导入第 {0}/{1} 次失败:{2};10 秒后重试(导入按账号和日期幂等)" -f
|
||||
$attempt, $attempts, $_.Exception.Message)
|
||||
Start-Sleep -Seconds 10
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($importExit -ne 0) {
|
||||
throw '网商银行账单导入失败;原有动账明细未改变'
|
||||
if (-not $importCompleted) {
|
||||
throw '网商银行账单导入失败;已重试 3 次,原有动账明细未改变'
|
||||
}
|
||||
} finally {
|
||||
Stop-CaiwuDeploymentAuth $auth
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user