From 69072078fb50e2415600fdfc21bf37a5037a5658 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20Ioni=C8=9B=C4=83?= Date: Sun, 24 Nov 2024 15:53:44 +0200 Subject: [PATCH] fix: add download jitter (#90) --- app/Models/ScheduledJob.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/Models/ScheduledJob.php b/app/Models/ScheduledJob.php index 021413e..041a59d 100644 --- a/app/Models/ScheduledJob.php +++ b/app/Models/ScheduledJob.php @@ -107,6 +107,9 @@ public function getPreparedSourceUrl(array $map = []): string public function fetchSource(array $map = []): Response { + // Jitter to prevent rate limiting + usleep(1000 * rand(1, 256)); + return Http::createPendingRequest() ->when($this->requiresAuthentication(), function (PendingRequest $request) { return $request->withBasicAuth($this->source_username, $this->source_password);