Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[10.x] [DRAFT] Bus chained unique jobs dispatched multiple times should process only once #49294

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions tests/Integration/Queue/JobChainingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Bus\Batchable;
use Illuminate\Bus\PendingBatch;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Foundation\Bus\PendingChain;
Expand Down Expand Up @@ -459,6 +460,18 @@ public function testChainBatchFailureNotAllowed()
$this->assertEquals(['batch failed', 'chain failed'], JobRunRecorder::$failures);
}

public function testChainBatchUniqueJobFiresAtLeastOnce()
{
Bus::chain([
new JobChainingTestUniqueJob('c1'),
new JobChainingTestUniqueJob('c2'),
new JobChainingTestUniqueJob('c3'),
new JobChainingTestUniqueJob('c4'),
])->dispatch();

$this->assertEquals(['c1'], JobRunRecorder::$results);
}

public function testChainConditionable()
{
$chain = Bus::chain([])
Expand Down Expand Up @@ -692,6 +705,25 @@ public function handle()
}
}

class JobChainingTestUniqueJob implements ShouldBeUnique
{
use Dispatchable, InteractsWithQueue, Queueable;

public static $results = [];

public string $id;

public function __construct(string $id)
{
$this->id = $id;
}

public function handle()
{
JobRunRecorder::record($this->id);
}
}

class JobRunRecorder
{
public static $results = [];
Expand Down