From 77a379d4ecd9172420527370df81d6533e671249 Mon Sep 17 00:00:00 2001 From: Hamed Kamrava Date: Fri, 13 May 2022 18:47:48 +0300 Subject: [PATCH 1/2] add queue tries --- src/FairSignalJob.php | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/FairSignalJob.php b/src/FairSignalJob.php index 0e3899e..f6a8892 100644 --- a/src/FairSignalJob.php +++ b/src/FairSignalJob.php @@ -76,7 +76,11 @@ public function handle() $jobSerialized = serialize($job); - $maxTries = $job->maxTries ?? 1; + $maxTries = $job->maxTries ?? false; + + if(!$maxTries) { + $maxTries = $this->getQueueTries($this->queue) ?? 1; + } if ($job->tries >= $maxTries) { $repository->pushFailed($this->queue, $partition, $jobSerialized); @@ -93,6 +97,23 @@ public function handle() } } + public function getQueueTries($queue) + { + if(!$queue) { + $queue = 'default'; + } + + // get queue tries from fair-queue config + $tries = config("fair-queue.queues.{$queue}.tries"); + + // sanity check + if(!$tries) { + $tries = config('fair-queue.queues.default.tries'); + } + + return $tries; + } + public function addToPartition() { /** @var RepositoryInterface $repository */ From 5f5a4caa9844dd627b899a37065761ad411521c2 Mon Sep 17 00:00:00 2001 From: Hamed Kamrava Date: Fri, 13 May 2022 20:41:14 +0300 Subject: [PATCH 2/2] add default config for retry --- config/fair-queue.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/config/fair-queue.php b/config/fair-queue.php index 1ce49cf..8affa8d 100644 --- a/config/fair-queue.php +++ b/config/fair-queue.php @@ -22,6 +22,19 @@ */ 'middleware' => ['web'], + /* + |-------------------------------------------------------------------------- + | FairQueue Queue Tries + |-------------------------------------------------------------------------- + | + | After a jobs how many times it should requeue? You can specify the + | number of tries here. + | + */ + 'queues' => [ + 'default' => ['tries' => 3], + ], + /* |-------------------------------------------------------------------------- | FairQueue Redis DB