Skip to content

Commit b556cbb

Browse files
[12.x] ChainedBatch keeps queue and connection of wrapped batch (#57630)
* [12.x] Test. ChainedBatch does not keep queue and connection of pending batch * [12.x] using redis cluster compatible queue name in test * [12.x] ChainedBatch keeps queue and connection of pending batch * Add queue and connection properties to ChainedBatch --------- Co-authored-by: Taylor Otwell <taylor@laravel.com>
1 parent 361f3fc commit b556cbb

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/Illuminate/Bus/ChainedBatch.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ public function __construct(PendingBatch $batch)
4646

4747
$this->name = $batch->name;
4848
$this->options = $batch->options;
49+
50+
$this->queue = $batch->queue();
51+
$this->connection = $batch->connection();
4952
}
5053

5154
/**

tests/Integration/Queue/JobChainingTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,26 @@ public function testBatchCanBeAddedToChain()
396396
$this->assertEquals(['c1', 'c2', 'b1', 'b2', 'b3', 'b4', 'c3'], JobRunRecorder::$results);
397397
}
398398

399+
public function testBatchInChainUsesCorrectQueue()
400+
{
401+
$otherQueue = $this->getQueueDriver() === 'redis' ? '{other}' : 'other';
402+
Bus::chain([
403+
(new JobChainingNamedTestJob('c1'))->onQueue($otherQueue),
404+
(new JobChainingNamedTestJob('c2'))->onQueue($otherQueue),
405+
Bus::batch([
406+
new JobChainingTestBatchedJob('b1'),
407+
new JobChainingTestBatchedJob('b2'),
408+
new JobChainingTestBatchedJob('b3'),
409+
new JobChainingTestBatchedJob('b4'),
410+
])->onQueue($otherQueue),
411+
(new JobChainingNamedTestJob('c3'))->onQueue($otherQueue),
412+
])->dispatch();
413+
414+
$this->runQueueWorkerCommand(['--queue' => $otherQueue, '--stop-when-empty' => true]);
415+
416+
$this->assertEquals(['c1', 'c2', 'b1', 'b2', 'b3', 'b4', 'c3'], JobRunRecorder::$results);
417+
}
418+
399419
public function testDynamicBatchCanBeAddedToChain()
400420
{
401421
Bus::chain([

0 commit comments

Comments
 (0)