Skip to content

Commit

Permalink
[8.x] Ensure ShouldBeUniqueUntilProcessing job lock is released once (#…
Browse files Browse the repository at this point in the history
…35270)

* [8.x] Ensure unique lock is released once

* Update CallQueuedHandler.php

Co-authored-by: Taylor Otwell <taylor@laravel.com>
  • Loading branch information
paras-malhotra and taylorotwell committed Nov 18, 2020
1 parent a4be47a commit d09bf01
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions src/Illuminate/Queue/CallQueuedHandler.php
Expand Up @@ -30,13 +30,6 @@ class CallQueuedHandler
*/
protected $container;

/**
* Indicates if the unique job lock has been released.
*
* @var bool
*/
protected $uniqueLockReleased = false;

/**
* Create a new handler instance.
*
Expand Down Expand Up @@ -73,7 +66,7 @@ public function call(Job $job, array $data)

$this->dispatchThroughMiddleware($job, $command);

if (! $job->isReleased()) {
if (! $job->isReleased() && ! $command instanceof ShouldBeUniqueUntilProcessing) {
$this->ensureUniqueJobLockIsReleased($command);
}

Expand Down Expand Up @@ -179,7 +172,7 @@ protected function ensureSuccessfulBatchJobIsRecorded($command)
*/
protected function ensureUniqueJobLockIsReleased($command)
{
if (! $command instanceof ShouldBeUnique || $this->uniqueLockReleased) {
if (! $command instanceof ShouldBeUnique) {
return;
}

Expand All @@ -194,8 +187,6 @@ protected function ensureUniqueJobLockIsReleased($command)
$cache->lock(
'laravel_unique_job:'.get_class($command).$uniqueId
)->forceRelease();

$this->uniqueLockReleased = true;
}

/**
Expand Down Expand Up @@ -237,7 +228,10 @@ public function failed(array $data, $e, string $uuid)
{
$command = unserialize($data['command']);

$this->ensureUniqueJobLockIsReleased($command);
if (! $command instanceof ShouldBeUniqueUntilProcessing) {
$this->ensureUniqueJobLockIsReleased($command);
}

$this->ensureFailedBatchJobIsRecorded($uuid, $command, $e);
$this->ensureChainCatchCallbacksAreInvoked($uuid, $command, $e);

Expand Down

0 comments on commit d09bf01

Please sign in to comment.