From a2255eb14f9bad49898b7628df1ce8855a2187f2 Mon Sep 17 00:00:00 2001 From: bucolucas Date: Tue, 20 Aug 2024 17:58:40 -0500 Subject: [PATCH 1/3] Add test check before running the main Python script. --- run_python_with_restart.ps1 | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/run_python_with_restart.ps1 b/run_python_with_restart.ps1 index 838d5f3..e6410ea 100644 --- a/run_python_with_restart.ps1 +++ b/run_python_with_restart.ps1 @@ -9,6 +9,11 @@ function Run-PythonScript { return $process.ExitCode } +function Run-Tests { + $process = Start-Process -FilePath "powershell" -ArgumentList "-File run_tests.ps1" -PassThru -Wait -NoNewWindow + return $process.ExitCode +} + function Git-Pull { git pull return $LASTEXITCODE -eq 0 @@ -17,6 +22,17 @@ function Git-Pull { $waitTime = 15 while ($true) { python -m pip install -r requirements.txt + + Write-Host "Running tests..." + $testExitCode = Run-Tests + if ($testExitCode -ne 0) { + Write-Host "Tests failed. Waiting $waitTime seconds before next attempt..." + Start-Sleep -Seconds $waitTime + $waitTime *= 2 + continue + } + + Write-Host "Tests passed. Starting main Python script..." $exitCode = Run-PythonScript -ScriptPath $PythonFile if (Test-Path -Path ".\.doreboot") { From c6f2c39ef86e889a2b85104eedef9ceea1548206 Mon Sep 17 00:00:00 2001 From: bucolucas Date: Tue, 20 Aug 2024 18:01:43 -0500 Subject: [PATCH 2/3] Add git pull during test loop if tests fail --- run_python_with_restart.ps1 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/run_python_with_restart.ps1 b/run_python_with_restart.ps1 index e6410ea..bc88915 100644 --- a/run_python_with_restart.ps1 +++ b/run_python_with_restart.ps1 @@ -26,7 +26,8 @@ while ($true) { Write-Host "Running tests..." $testExitCode = Run-Tests if ($testExitCode -ne 0) { - Write-Host "Tests failed. Waiting $waitTime seconds before next attempt..." + Write-Host "Tests failed. Attempting git pull and waiting $waitTime seconds before next attempt..." + Git-Pull Start-Sleep -Seconds $waitTime $waitTime *= 2 continue From e63bcbb1a23a3141dc8da48bb545f811d192b1bf Mon Sep 17 00:00:00 2001 From: bucolucas Date: Tue, 20 Aug 2024 18:04:06 -0500 Subject: [PATCH 3/3] Set flat 30-second wait time between test retries --- run_python_with_restart.ps1 | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/run_python_with_restart.ps1 b/run_python_with_restart.ps1 index bc88915..1f7625f 100644 --- a/run_python_with_restart.ps1 +++ b/run_python_with_restart.ps1 @@ -19,7 +19,7 @@ function Git-Pull { return $LASTEXITCODE -eq 0 } -$waitTime = 15 +$waitTime = 30 while ($true) { python -m pip install -r requirements.txt @@ -29,7 +29,6 @@ while ($true) { Write-Host "Tests failed. Attempting git pull and waiting $waitTime seconds before next attempt..." Git-Pull Start-Sleep -Seconds $waitTime - $waitTime *= 2 continue } @@ -41,7 +40,6 @@ while ($true) { if (Git-Pull) { Write-Host "Git pull successful. Restarting Python script..." - $waitTime = 15 continue } else { Write-Host "Git pull failed. Waiting $waitTime seconds before next attempt..." @@ -51,5 +49,4 @@ while ($true) { } Start-Sleep -Seconds $waitTime - $waitTime *= 2 } \ No newline at end of file