Harden scheduler and stale breakout reentry

This commit is contained in:
whdwo
2026-06-15 18:52:42 +09:00
parent eac4ece01e
commit 901243348e
16 changed files with 181 additions and 61 deletions
+10 -3
View File
@@ -30,6 +30,7 @@ function Register-StockTask {
$Settings = New-ScheduledTaskSettingsSet `
-ExecutionTimeLimit (New-TimeSpan -Minutes $LimitMinutes) `
-StartWhenAvailable `
-WakeToRun `
-DontStopIfGoingOnBatteries `
-RunOnlyIfNetworkAvailable:$false
$Settings.DisallowStartIfOnBatteries = $false
@@ -47,15 +48,21 @@ function Register-StockTask {
}
function Register-WatchdogTask {
$TaskName = "\StockBot\StockBot_Watchdog"
$ScriptPath = Join-Path $Project "scripts\run_watchdog.ps1"
$Command = 'schtasks /Create /TN "\StockBot\StockBot_Watchdog" /TR "\"powershell.exe\" -NonInteractive -ExecutionPolicy Bypass -File \"' + $ScriptPath + '\"" /SC MINUTE /MO 5 /ST 09:00 /ET 15:10 /F'
$Command = 'schtasks /Create /TN "\StockBot\StockBot_Watchdog" /TR "\"powershell.exe\" -NonInteractive -ExecutionPolicy Bypass -File \"' + $ScriptPath + '\"" /SC WEEKLY /D MON,TUE,WED,THU,FRI /ST 09:00 /RI 5 /DU 06:05 /F'
cmd.exe /c $Command | Out-Null
if ($LASTEXITCODE -ne 0) {
throw "StockBot_Watchdog registration failed"
}
Write-Host "[OK] StockBot_Watchdog registered at 09:00-15:10 every 5 minutes" -ForegroundColor Green
$Task = Get-ScheduledTask -TaskName "StockBot_Watchdog" -TaskPath $TaskPath
$Task.Settings.StartWhenAvailable = $true
$Task.Settings.WakeToRun = $true
$Task.Settings.DisallowStartIfOnBatteries = $false
$Task.Settings.StopIfGoingOnBatteries = $false
Set-ScheduledTask -TaskName "StockBot_Watchdog" -TaskPath $TaskPath -Settings $Task.Settings | Out-Null
Write-Host "[OK] StockBot_Watchdog registered weekdays at 09:00-15:05 every 5 minutes" -ForegroundColor Green
}
Register-StockTask "StockBot_Morning" "08:15" "run_morning.ps1" 20