Add sleep between seeded offers
All checks were successful
Build Docker Image / build (push) Successful in 2m7s

This commit is contained in:
Ruslan Bakiev
2026-02-05 01:45:55 +07:00
parent c654d25230
commit 1e8b5ad859

View File

@@ -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