봇 무음 크래시 방지 — trading_loop 예외 처리 + 워치독 추가
- app/main.py: trading_loop while 루프 전체를 try/except로 감싸 예외 발생 시 로그+Discord 알림 후 루프 재개 (연속 10회 오류 시에만 종료) - scripts/_watchdog.py: 봇 PID 생존 확인, 죽어있으면 Discord 알림 + 자동 재시작 - scripts/run_watchdog.ps1: 워치독 PowerShell 래퍼 - scripts/setup_scheduler.ps1: StockBot_Watchdog 태스크 등록 추가 (5분 간격) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -42,7 +42,7 @@ function Register-StockTask($name, $time, $script, $limitMin) {
|
||||
Write-Host "[OK] $name 등록 완료 (평일 $time)" -ForegroundColor Green
|
||||
}
|
||||
|
||||
# ── 3개 태스크 등록 (StockBot_Bot 제거 — /morning이 /start-bot을 호출함) ────
|
||||
# ── 태스크 등록 ────────────────────────────────────────────────────────────────
|
||||
# 08:15 claude /morning → 뉴스+KIS 수집 → daily_context.json → /start-bot 호출
|
||||
Register-StockTask "StockBot_Morning" "08:15" "run_morning.ps1" 20
|
||||
|
||||
@@ -52,6 +52,34 @@ Register-StockTask "StockBot_Midday" "11:20" "run_midday.ps1" 20
|
||||
# 15:30 claude /evening → 결과 분석 → 리포트 → Discord
|
||||
Register-StockTask "StockBot_Evening" "15:30" "run_evening.ps1" 30
|
||||
|
||||
# 워치독: 5분마다 봇 생존 확인 → 죽어있으면 Discord 알림 + 자동 재시작
|
||||
function Register-WatchdogTask {
|
||||
$times = @("09:00","09:05","09:10","09:15","09:20","09:25","09:30","09:35","09:40","09:45","09:50","09:55",
|
||||
"10:00","10:05","10:10","10:15","10:20","10:25","10:30","10:35","10:40","10:45","10:50","10:55",
|
||||
"11:00","11:05","11:10","11:15","11:20","11:25","11:30","11:35","11:40","11:45","11:50","11:55",
|
||||
"12:00","12:05","12:10","12:15","12:20","12:25","12:30","12:35","12:40","12:45","12:50","12:55",
|
||||
"13:00","13:05","13:10","13:15","13:20","13:25","13:30","13:35","13:40","13:45","13:50","13:55",
|
||||
"14:00","14:05","14:10","14:15","14:20","14:25","14:30","14:35","14:40","14:45","14:50","14:55",
|
||||
"15:00","15:05","15:10")
|
||||
$triggers = $times | ForEach-Object {
|
||||
New-ScheduledTaskTrigger -Weekly -DaysOfWeek $weekdays -At $_
|
||||
}
|
||||
$action = New-ScheduledTaskAction `
|
||||
-Execute "powershell.exe" `
|
||||
-Argument "-NonInteractive -ExecutionPolicy Bypass -File `"$PROJECT\scripts\run_watchdog.ps1`"" `
|
||||
-WorkingDirectory $PROJECT
|
||||
$settings = New-ScheduledTaskSettingsSet `
|
||||
-ExecutionTimeLimit (New-TimeSpan -Minutes 3) `
|
||||
-StartWhenAvailable `
|
||||
-MultipleInstances IgnoreNew `
|
||||
-DontStopIfGoingOnBatteries
|
||||
$settings.DisallowStartIfOnBatteries = $false
|
||||
Register-ScheduledTask -TaskName "StockBot_Watchdog" -TaskPath "\StockBot\" `
|
||||
-Trigger $triggers -Action $action -Settings $settings -RunLevel Limited -Force | Out-Null
|
||||
Write-Host "[OK] StockBot_Watchdog 등록 완료 (평일 09:00~15:10, 5분 간격)" -ForegroundColor Green
|
||||
}
|
||||
Register-WatchdogTask
|
||||
|
||||
# StockBot_Bot 비활성화 유지 (이미 존재할 경우)
|
||||
$botTask = Get-ScheduledTask -TaskName "StockBot_Bot" -TaskPath "\StockBot\" -ErrorAction SilentlyContinue
|
||||
if ($botTask) {
|
||||
|
||||
Reference in New Issue
Block a user