Add entropy to retries to prevent jobs queuing at the exact same time

This commit is contained in:
David Bomba 2023-04-01 10:35:10 +11:00
parent 82f7c376db
commit 1611f27665
4 changed files with 11 additions and 1 deletions

View File

@ -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]);
}

View File

@ -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]);
}
}

View File

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

View File

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