From 1e28702f962f97edc9d4c1e1bba3171b2ab26f3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20L=C3=B8vgaard?= Date: Wed, 27 Nov 2024 11:14:16 +0100 Subject: [PATCH] Change the delay so that we don't change the delay every 4 entities but instead every 240 --- .../UploadProductVariantRequestProcessor.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Processor/UploadProductVariantRequestProcessor.php b/src/Processor/UploadProductVariantRequestProcessor.php index 8aeccf7..9267fe7 100644 --- a/src/Processor/UploadProductVariantRequestProcessor.php +++ b/src/Processor/UploadProductVariantRequestProcessor.php @@ -48,12 +48,16 @@ public function process(): void ++$i; // According to https://api.peakwms.com/api/documentation/index.html the rate limit is 240 requests per minute - // So we will increase the delay by 1 second every 4 iterations (240 / 60 = 4) - if ($i % 4 === 0) { - $delay += 1000; + if ($i % 240 === 0) { + $delay += 60_000; } - $this->commandBus->dispatch(new ProcessUploadProductVariantRequest($uploadProductVariantRequest), [new DelayStamp($delay)]); + $stamps = []; + if ($delay > 0) { + $stamps[] = new DelayStamp($delay); + } + + $this->commandBus->dispatch(new ProcessUploadProductVariantRequest($uploadProductVariantRequest), $stamps); } } }