From 1611f276659805e09f8205519c30008d3073b49a Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sat, 1 Apr 2023 10:35:10 +1100 Subject: [PATCH] Add entropy to retries to prevent jobs queuing at the exact same time --- app/Jobs/Mail/NinjaMailerJob.php | 2 ++ app/Jobs/Util/WebhookSingle.php | 5 ++++- app/Services/Email/Email.php | 3 +++ app/Services/Email/EmailMailer.php | 2 ++ 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/Jobs/Mail/NinjaMailerJob.php b/app/Jobs/Mail/NinjaMailerJob.php index ee93b4156d43..1254bd666b76 100644 --- a/app/Jobs/Mail/NinjaMailerJob.php +++ b/app/Jobs/Mail/NinjaMailerJob.php @@ -188,6 +188,8 @@ class NinjaMailerJob implements ShouldQueue } /* Releasing immediately does not add in the backoff */ + sleep(rand(0, 3)); + $this->release($this->backoff()[$this->attempts()-1]); } diff --git a/app/Jobs/Util/WebhookSingle.php b/app/Jobs/Util/WebhookSingle.php index ab5bd5af1710..29fd766fb2cd 100644 --- a/app/Jobs/Util/WebhookSingle.php +++ b/app/Jobs/Util/WebhookSingle.php @@ -63,7 +63,7 @@ class WebhookSingle implements ShouldQueue public function backoff() { - return [10, 30, 60, 180, 3600]; + return [15, 35, 65, 185, 3605]; } /** @@ -223,6 +223,9 @@ class WebhookSingle implements ShouldQueue $this->company, ))->handle(); + //add some entropy to the retry + sleep(rand(0, 3)); + $this->release($this->backoff()[$this->attempts()-1]); } } diff --git a/app/Services/Email/Email.php b/app/Services/Email/Email.php index 4f68a139be7c..9ff36f5c52e6 100644 --- a/app/Services/Email/Email.php +++ b/app/Services/Email/Email.php @@ -309,6 +309,9 @@ class Email implements ShouldQueue $this->tearDown(); /* Releasing immediately does not add in the backoff */ + + sleep(rand(0, 3)); + $this->release($this->backoff()[$this->attempts()-1]); $message = null; diff --git a/app/Services/Email/EmailMailer.php b/app/Services/Email/EmailMailer.php index 4aa296f270df..6d633575bc01 100644 --- a/app/Services/Email/EmailMailer.php +++ b/app/Services/Email/EmailMailer.php @@ -136,6 +136,8 @@ class EmailMailer implements ShouldQueue /* Releasing immediately does not add in the backoff */ + sleep(rand(0, 3)); + $this->release($this->backoff()[$this->attempts()-1]); $message = null;