Skip to content

Commit

Permalink
Remove interface and check method/property instead
Browse files Browse the repository at this point in the history
  • Loading branch information
paras-malhotra committed Nov 3, 2020
1 parent e2067d3 commit bc45489
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 16 deletions.
8 changes: 0 additions & 8 deletions src/Illuminate/Contracts/Queue/UniqueJob.php

This file was deleted.

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,7 +5,6 @@
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 @@ -131,7 +130,8 @@ public function afterResponse()
*/
protected function shouldDispatch()
{
if (! ($this->job instanceof UniqueJob)) {
if (! method_exists($this->job, 'uniqueId')
&& ! property_exists($this->job, 'uniqueId')) {
return true;
}

Expand Down
1 change: 0 additions & 1 deletion src/Illuminate/Foundation/Console/stubs/job.queued.stub
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ 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,7 +8,6 @@
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 @@ -167,7 +166,8 @@ protected function ensureSuccessfulBatchJobIsRecorded($command)
*/
protected function ensureUniqueJobLockIsReleased($command)
{
if ($command instanceof UniqueJob) {
if (method_exists($command, 'uniqueId')
|| property_exists($command, 'uniqueId')) {
$uniqueId = method_exists($command, 'uniqueId')
? $command->uniqueId()
: ($command->uniqueId ?? '');
Expand Down
9 changes: 6 additions & 3 deletions tests/Integration/Queue/UniqueJobTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
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 @@ -146,24 +145,28 @@ protected function getLockKey($job)
}
}

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

public static $handled = false;

public $uniqueId = '';

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

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

public $tries = 1;

public $uniqueId = '';

public static $handled = false;

public function handle()
Expand Down

0 comments on commit bc45489

Please sign in to comment.