fix: auto-restart scanner on crash with Telegram notification
Wrap run_scanner() in while True loop so main thread recovers from unhandled exceptions. Sends Telegram alert on crash before restarting. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
14
main.py
14
main.py
@@ -18,7 +18,7 @@ logging.basicConfig(
|
||||
)
|
||||
|
||||
from core.monitor import run_monitor
|
||||
from core.notify import notify_status
|
||||
from core.notify import notify_error, notify_status
|
||||
from core.trader import get_positions, restore_positions
|
||||
from daemon.runner import run_scanner
|
||||
|
||||
@@ -39,6 +39,8 @@ def run_status_reporter(interval: int = STATUS_INTERVAL) -> None:
|
||||
|
||||
|
||||
def main() -> None:
|
||||
logger = logging.getLogger("main")
|
||||
|
||||
# 재시작 시 기존 잔고 복원 (이중 매수 방지)
|
||||
restore_positions()
|
||||
|
||||
@@ -54,8 +56,14 @@ def main() -> None:
|
||||
)
|
||||
status_thread.start()
|
||||
|
||||
# 매수 스캔 루프 (60초 주기, 메인 스레드)
|
||||
run_scanner()
|
||||
# 매수 스캔 루프 (60초 주기, 메인 스레드) — 예외 발생 시 Telegram 알림 후 재시작
|
||||
while True:
|
||||
try:
|
||||
run_scanner()
|
||||
except Exception as e:
|
||||
logger.error(f"스캐너 비정상 종료: {e}", exc_info=True)
|
||||
notify_error(f"스캐너 비정상 종료: {e}\n5초 후 재시작합니다.")
|
||||
time.sleep(5)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user