import sys

from django.apps import AppConfig


class DevicesConfig(AppConfig):
    name = 'sandbox.apps.devices'

    def ready(self):
        # Import signals
        import sandbox.apps.devices.signals

        # Avoid django.db.utils.OperationalError: no such table: background_task:
        if all([
                any(s.endswith('manage.py') for s in sys.argv),
        ]):
            return

        # Initialize background tasks
        from sandbox.apps.devices.tasks import update_model_on_snapd_responses
        update_model_on_snapd_responses(repeat=1)
