Skip to content

Commit

Permalink
add interface
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Nov 18, 2020
1 parent 2a6e9d3 commit b53f13e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace Illuminate\Contracts\Queue;

interface ShouldBeUniqueUntilProcessing extends ShouldBeUnique
{
//
}
5 changes: 3 additions & 2 deletions src/Illuminate/Queue/CallQueuedHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Illuminate\Contracts\Container\Container;
use Illuminate\Contracts\Queue\Job;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldBeUniqueUntilProcessing;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Pipeline\Pipeline;
use ReflectionClass;
Expand Down Expand Up @@ -66,7 +67,7 @@ public function call(Job $job, array $data)
return $this->handleModelNotFound($job, $e);
}

if ($command->uniqueUntilStart ?? false) {
if ($command instanceof ShouldBeUniqueUntilProcessing) {
$this->ensureUniqueJobLockIsReleased($command);
}

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

Expand Down
5 changes: 2 additions & 3 deletions tests/Integration/Queue/UniqueJobTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Cache\Repository as Cache;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldBeUniqueUntilProcessing;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Foundation\Bus\Dispatchable;
Expand Down Expand Up @@ -215,11 +216,9 @@ class UniqueTestRetryJob extends UniqueTestFailJob
public $connection = 'database';
}

class UniqueUntilStartTestJob extends UniqueTestJob
class UniqueUntilStartTestJob extends UniqueTestJob implements ShouldBeUniqueUntilProcessing
{
public $tries = 2;

public $connection = 'database';

public $uniqueUntilStart = true;
}

0 comments on commit b53f13e

Please sign in to comment.