Harden scheduler and stale breakout reentry
This commit is contained in:
@@ -85,7 +85,7 @@ async def main():
|
||||
now = datetime.now()
|
||||
now_str = now.strftime("%H:%M")
|
||||
|
||||
if not ("09:00" <= now_str <= "15:10"):
|
||||
if not ("09:00" <= now_str < "15:10"):
|
||||
print(f"[{now_str}] outside trading window - watchdog skipped")
|
||||
return
|
||||
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
chcp 65001 | Out-Null
|
||||
$OutputEncoding = [System.Text.Encoding]::UTF8
|
||||
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
|
||||
$env:PYTHONUTF8 = "1"
|
||||
$env:PYTHONIOENCODING = "utf-8"
|
||||
|
||||
$Root = Split-Path -Parent (Split-Path -Parent $MyInvocation.MyCommand.Path)
|
||||
Set-Location $Root
|
||||
. "$Root\scripts\stockbot_env.ps1"
|
||||
|
||||
@@ -27,7 +27,7 @@ if ($LASTEXITCODE -ne 0) {
|
||||
|
||||
$now = Get-Date
|
||||
$start = Get-Date -Hour 9 -Minute 0 -Second 0
|
||||
$end = Get-Date -Hour 15 -Minute 10 -Second 59
|
||||
$end = Get-Date -Hour 15 -Minute 9 -Second 59
|
||||
if ($now -lt $start -or $now -gt $end) {
|
||||
Write-WatchdogLog "outside watchdog window - skipped"
|
||||
exit 0
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user