From 1e8b5ad85995cab7f0cc4440f006da6fe5d45afb Mon Sep 17 00:00:00 2001 From: Ruslan Bakiev Date: Thu, 5 Feb 2026 01:45:55 +0700 Subject: [PATCH] Add sleep between seeded offers --- offers/management/commands/seed_exchange.py | 24 +++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/offers/management/commands/seed_exchange.py b/offers/management/commands/seed_exchange.py index ad39128..0c66e5d 100644 --- a/offers/management/commands/seed_exchange.py +++ b/offers/management/commands/seed_exchange.py @@ -5,6 +5,7 @@ Creates offers via Temporal workflow so they sync to the graph. import random import uuid from decimal import Decimal +import time import requests from django.core.management.base import BaseCommand @@ -128,6 +129,12 @@ class Command(BaseCommand): default=200, help="Batch size for bulk_create (default: 200)", ) + parser.add_argument( + "--sleep-ms", + type=int, + default=0, + help="Sleep between offer creations in milliseconds (default: 0)", + ) parser.add_argument( "--geo-url", type=str, @@ -186,6 +193,7 @@ class Command(BaseCommand): use_workflow = not options["no_workflow"] use_bulk = options["bulk"] bulk_size = max(1, options["bulk_size"]) + sleep_ms = max(0, options["sleep_ms"]) geo_url = options["geo_url"] odoo_url = options["odoo_url"] product_filter = options["product"] @@ -244,7 +252,7 @@ class Command(BaseCommand): return if use_workflow: created_offers = self._create_offers_via_workflow( - offers_count, hubs, products, supplier_location_ratio + offers_count, hubs, products, supplier_location_ratio, sleep_ms ) elif use_bulk: created_offers = self._create_offers_direct_bulk( @@ -252,7 +260,7 @@ class Command(BaseCommand): ) else: created_offers = self._create_offers_direct( - offers_count, hubs, products, supplier_location_ratio + offers_count, hubs, products, supplier_location_ratio, sleep_ms ) self.stdout.write(self.style.SUCCESS(f"Created {len(created_offers)} offers")) @@ -620,7 +628,9 @@ class Command(BaseCommand): "longitude": supplier.longitude, } - def _create_offers_via_workflow(self, count: int, hubs: list, products: list, supplier_ratio: float) -> list: + def _create_offers_via_workflow( + self, count: int, hubs: list, products: list, supplier_ratio: float, sleep_ms: int + ) -> list: """Create offers via Temporal workflow (syncs to graph)""" created = [] suppliers = list(SupplierProfile.objects.all()) @@ -658,10 +668,14 @@ class Command(BaseCommand): created.append(offer_uuid) except Exception as e: self.stdout.write(self.style.ERROR(f" [{idx+1}/{count}] Failed: {e}")) + if sleep_ms: + time.sleep(sleep_ms / 1000.0) return created - def _create_offers_direct(self, count: int, hubs: list, products: list, supplier_ratio: float) -> list: + def _create_offers_direct( + self, count: int, hubs: list, products: list, supplier_ratio: float, sleep_ms: int + ) -> list: """Create offers directly in DB (no workflow, no graph sync)""" created = [] suppliers = list(SupplierProfile.objects.all()) @@ -696,6 +710,8 @@ class Command(BaseCommand): description=f"{product_name} available from {hub['name']} in {hub['country']}", ) created.append(offer) + if sleep_ms: + time.sleep(sleep_ms / 1000.0) return created