Skip to content

Commit

Permalink
Revert "Remove interface and check method/property instead"
Browse files Browse the repository at this point in the history
This reverts commit bc45489.
  • Loading branch information
paras-malhotra committed Nov 3, 2020
1 parent bc45489 commit 7c5a18c
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 10 deletions.
8 changes: 8 additions & 0 deletions src/Illuminate/Contracts/Queue/UniqueJob.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace Illuminate\Contracts\Queue;

interface UniqueJob
{
//
}
4 changes: 2 additions & 2 deletions src/Illuminate/Foundation/Bus/PendingDispatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Container\Container;
use Illuminate\Contracts\Bus\Dispatcher;
use Illuminate\Contracts\Cache\Repository as Cache;
use Illuminate\Contracts\Queue\UniqueJob;

class PendingDispatch
{
Expand Down Expand Up @@ -130,8 +131,7 @@ public function afterResponse()
*/
protected function shouldDispatch()
{
if (! method_exists($this->job, 'uniqueId')
&& ! property_exists($this->job, 'uniqueId')) {
if (! ($this->job instanceof UniqueJob)) {
return true;
}

Expand Down
1 change: 1 addition & 0 deletions src/Illuminate/Foundation/Console/stubs/job.queued.stub
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ namespace {{ namespace }};

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Contracts\Queue\UniqueJob;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
Expand Down
4 changes: 2 additions & 2 deletions src/Illuminate/Queue/CallQueuedHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Illuminate\Contracts\Cache\Repository as Cache;
use Illuminate\Contracts\Container\Container;
use Illuminate\Contracts\Queue\Job;
use Illuminate\Contracts\Queue\UniqueJob;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Pipeline\Pipeline;
use ReflectionClass;
Expand Down Expand Up @@ -166,8 +167,7 @@ protected function ensureSuccessfulBatchJobIsRecorded($command)
*/
protected function ensureUniqueJobLockIsReleased($command)
{
if (method_exists($command, 'uniqueId')
|| property_exists($command, 'uniqueId')) {
if ($command instanceof UniqueJob) {
$uniqueId = method_exists($command, 'uniqueId')
? $command->uniqueId()
: ($command->uniqueId ?? '');
Expand Down
9 changes: 3 additions & 6 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\ShouldQueue;
use Illuminate\Contracts\Queue\UniqueJob;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
Expand Down Expand Up @@ -145,28 +146,24 @@ protected function getLockKey($job)
}
}

class UniqueTestJob implements ShouldQueue
class UniqueTestJob implements ShouldQueue, UniqueJob
{
use InteractsWithQueue, Queueable, Dispatchable;

public static $handled = false;

public $uniqueId = '';

public function handle()
{
static::$handled = true;
}
}

class UniqueTestFailJob implements ShouldQueue
class UniqueTestFailJob implements ShouldQueue, UniqueJob
{
use InteractsWithQueue, Queueable, Dispatchable;

public $tries = 1;

public $uniqueId = '';

public static $handled = false;

public function handle()
Expand Down

0 comments on commit 7c5a18c

Please sign in to comment.