Skip to content

Commit

Permalink
Merge pull request #16 from aloware/add-queue-tries
Browse files Browse the repository at this point in the history
Feature | Add Queue Tries
  • Loading branch information
mohsen-aloware authored May 13, 2022
2 parents 6c42245 + 5f5a4ca commit b9d41ec
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
13 changes: 13 additions & 0 deletions config/fair-queue.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 22 additions & 1 deletion src/FairSignalJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 */
Expand Down

0 comments on commit b9d41ec

Please sign in to comment.