#!/usr/bin/env python3
# SPDX-License-Identifier: GPL-2.0-or-later
import logging
import traceback
from vyos.wan_handover_runtime import Controller
from vyos.wan_handover_link import Events

logging.basicConfig(level=logging.INFO)
controller = Controller()
events = Events()
while True:
    try:
        controller.tick()
    except Exception as error:
        frames = traceback.extract_tb(error.__traceback__)
        location = frames[-1] if frames else None
        logging.error('WAN controller retry (%s at %s:%s)', type(error).__name__,
                      location.filename if location else '?', location.lineno if location else '?')
    events.wait(timeout=1)
