Watch
1
0
Fork
You've already forked Seyyed_arc
0
forked from hesabix/arc
Seyyed_arc/extraScripts/migration/holoo2hesabix/scripts/watchdog-full-e2e.ps1
Babak Alizadeh a5875e7a3a Release Holoo2Hesabix 1.1.0 with production-ready accounting migration.
Harden Holoo-to-Hesabix document partition/mapping, sample E2E tooling, remove hardcoded SQL credentials from scripts, fix income AR account 10401, and publish Setup MSI 1.1.0.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-24 15:56:40 +03:30

65 lines
2 KiB
PowerShell

# Watchdog: keep full E2E running until invoices reach Holoo count (or max hours).
param(
[int]$BusinessId = 6823,
[int]$TargetInvoices = 22789,
[int]$MaxHours = 36,
[string]$RunScript = "d:\hesabixArc\extraScripts\migration\holoo2hesabix\scripts\run-full-e2e.ps1"
)
$ErrorActionPreference = "Continue"
$log = "d:\hesabixArc\.eyeban\e2e-watchdog.txt"
$pidFile = "d:\hesabixArc\.eyeban\e2e-full-pid.txt"
$deadline = (Get-Date).AddHours($MaxHours)
function Log([string]$m) {
$line = "$(Get-Date -Format 's') $m"
Add-Content $log $line -Encoding UTF8
Write-Output $line
}
function DoneCount() {
try {
$j = Get-Content "$env:LOCALAPPDATA\Holoo2Hesabix\checkpoints\biz${BusinessId}_Holoo1.json" -Raw -Encoding UTF8 | ConvertFrom-Json
return @($j.Modules.Invoices.Done.PSObject.Properties).Count
} catch { return -1 }
}
function IsAlive() {
if (-not (Test-Path $pidFile)) { return $false }
$p = 0
try { $p = [int](Get-Content $pidFile -Raw).Trim() } catch { return $false }
if ($p -le 0) { return $false }
return [bool](Get-Process -Id $p -ErrorAction SilentlyContinue)
}
function StartTransfer() {
& powershell -NoProfile -ExecutionPolicy Bypass -File $RunScript -BusinessId $BusinessId
Start-Sleep -Seconds 4
}
Log "watchdog start target=$TargetInvoices maxHours=$MaxHours"
if (-not (IsAlive)) {
Log "starting initial transfer"
StartTransfer
}
while ((Get-Date) -lt $deadline) {
$d = DoneCount
$alive = IsAlive
Log "alive=$alive inv=$d/$TargetInvoices"
if ($d -ge $TargetInvoices) {
Log "TARGET REACHED inv=$d"
if ($alive) {
for ($i = 0; $i -lt 90; $i++) {
if (-not (IsAlive)) { break }
Start-Sleep -Seconds 30
}
}
Log "watchdog done"
exit 0
}
if (-not $alive) {
Log "process dead - restart from checkpoint"
StartTransfer
if (-not (IsAlive)) {
Log "restart FAILED"
Start-Sleep -Seconds 60
}
}
Start-Sleep -Seconds 120
}
Log "watchdog deadline reached inv=$(DoneCount)"
exit 2