# push_loop.ps1 — Resilient push runner: restarts batch_run.py on crash, # stops when all packages are done or budget exhausted. # Usage: .\push_loop.ps1 (run from C:\dev\skillfactor) Set-Location C:\dev\skillfactor $python = "C:\dev\skillfactor\.venv\Scripts\python.exe" $script = "pipeline/batch_run.py" $logBase = "docs\logs\pushloop" $run = 0 while ($true) { $run++ $logOut = "${logBase}_run${run}.log" $logErr = "${logBase}_run${run}-err.log" # Check if work is done $prog = Get-Content "data\progress.json" | ConvertFrom-Json $occs = $prog.occupations | Get-Member -MemberType NoteProperty | Select-Object -ExpandProperty Name $done = ($occs | Where-Object { $prog.occupations.$_.package -eq 'done' }).Count $total = $occs.Count Write-Output "[$(Get-Date -f 'HH:mm')] Run $run start: $done done / $total entries" if ($done -ge 3039) { Write-Output "Alle 3039 Pakete gepusht. Push-Loop fertig." break } # Start batch_run with stdout unbuffered $proc = Start-Process -FilePath $python ` -ArgumentList "-u $script --stage packages" ` -WorkingDirectory "C:\dev\skillfactor" ` -RedirectStandardOutput $logOut ` -RedirectStandardError $logErr ` -WindowStyle Hidden -PassThru -Wait $exitCode = $proc.ExitCode $newDone = (Get-Content "data\progress.json" | ConvertFrom-Json).occupations | Get-Member -MemberType NoteProperty | Select-Object -ExpandProperty Name | Where-Object { (Get-Content "data\progress.json" | ConvertFrom-Json).occupations.$_.package -eq 'done' } $newDone = @($newDone).Count Write-Output "[$(Get-Date -f 'HH:mm')] Run $run exit=$exitCode done=$newDone" if ($exitCode -eq 2) { Write-Output "Budget erschoepft. Stop." break } if ($newDone -ge 3039) { Write-Output "Alle 3039 fertig. Stop." break } # Brief pause before retry Start-Sleep -Seconds 3 }