Files
dashboard-cpsp/backend/apps/jobs/management/commands/sync_iot_from_api.py
T

24 lines
788 B
Python

from django.conf import settings
from django.core.management.base import BaseCommand
from apps.operations.services.iot_api import IotApiError, sync_iot_panels
class Command(BaseCommand):
help = "Sync IoT panel readings from the external IoT flocks API (10-minute snapshots)"
def handle(self, *args, **options):
if not settings.IOT_SYNC_ENABLED:
self.stdout.write("IOT_SYNC_ENABLED=false; skipping")
return
try:
summary = sync_iot_panels()
except IotApiError as exc:
self.stderr.write(str(exc))
return
self.stdout.write(
self.style.SUCCESS(
f"IoT sync OK: upserted={summary.upserted} skipped={summary.skipped} pages={summary.pages}"
)
)