from apscheduler.schedulers.background import BackgroundScheduler
from apscheduler.triggers.interval import IntervalTrigger
import logging

logger = logging.getLogger(__name__)

scheduler = BackgroundScheduler()


def start():
    if not scheduler.running:
        from device_interaction.tasks import check_device_online_status

        scheduler.add_job(
            check_device_online_status,
            trigger=IntervalTrigger(seconds=60),
            id='check_device_online_status',
            replace_existing=True,
        )
        logger.info("Device online check scheduler started")
        scheduler.start()


def stop():
    if scheduler.running:
        scheduler.shutdown()
        logger.info("Device online check scheduler stopped")
