update sync data from site dashboard and testing closing cycles
This commit is contained in:
1 parent
36639d8c38
commit
f49e72592c
42 files changed
+1966
-688
No files matched your search
@@ -0,0 +1,58 @@
|
||||
from django.conf import settings
|
||||
from django.core.management.base import BaseCommand
|
||||
|
||||
from apps.sync.services.mirror_pull import STATUS_OK, sync_all_active_sites
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = "Pull ops + IoT exports from registered ActiveSite farm APIs into the HQ mirror"
|
||||
|
||||
def add_arguments(self, parser):
|
||||
parser.add_argument(
|
||||
"--closed-limit",
|
||||
type=int,
|
||||
default=None,
|
||||
help="Last N closed cycles per kandang (default from settings)",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--page-size",
|
||||
type=int,
|
||||
default=None,
|
||||
help="Export page size (default from settings)",
|
||||
)
|
||||
|
||||
def handle(self, *args, **options):
|
||||
if not settings.ACTIVE_SITE_MIRROR_SYNC_ENABLED:
|
||||
self.stdout.write("ACTIVE_SITE_MIRROR_SYNC_ENABLED=false; skipping")
|
||||
return
|
||||
|
||||
closed_limit = options["closed_limit"]
|
||||
if closed_limit is None:
|
||||
closed_limit = settings.ACTIVE_SITE_MIRROR_CLOSED_LIMIT
|
||||
page_size = options["page_size"]
|
||||
if page_size is None:
|
||||
page_size = settings.ACTIVE_SITE_MIRROR_SYNC_PAGE_SIZE
|
||||
|
||||
summaries = sync_all_active_sites(
|
||||
closed_limit=closed_limit, page_size=page_size
|
||||
)
|
||||
if not summaries:
|
||||
self.stdout.write("No active sites with api_base_url/api_key to sync.")
|
||||
return
|
||||
|
||||
ok = 0
|
||||
for summary in summaries:
|
||||
line = (
|
||||
f"active_site={summary.active_site_id} status={summary.status} "
|
||||
f"cycles={summary.selected_cycles} iot={summary.iot_panels} "
|
||||
f"— {summary.message}"
|
||||
)
|
||||
if summary.status == STATUS_OK:
|
||||
ok += 1
|
||||
self.stdout.write(self.style.SUCCESS(line))
|
||||
else:
|
||||
self.stderr.write(line)
|
||||
|
||||
self.stdout.write(
|
||||
self.style.SUCCESS(f"Mirror sync done: {ok}/{len(summaries)} ok")
|
||||
)
|
||||
Reference in new issue
Block a user