Skip to content

Commit 0900dc5

Browse files
authored
feat(bus): allow adding multiple jobs to chain (#55668)
`prependToChain()` reverses the collection before inserting the jobs one by one to ensure that the first job is processed before the second one.
1 parent 30d92c9 commit 0900dc5

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/Illuminate/Bus/Queueable.php

+8-4
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,11 @@ public function chain($chain)
221221
*/
222222
public function prependToChain($job)
223223
{
224-
$jobs = ChainedBatch::prepareNestedBatches(new Collection([$job]));
224+
$jobs = ChainedBatch::prepareNestedBatches(Collection::wrap($job));
225225

226-
$this->chained = Arr::prepend($this->chained, $this->serializeJob($jobs->first()));
226+
foreach ($jobs->reverse() as $job) {
227+
$this->chained = Arr::prepend($this->chained, $this->serializeJob($job));
228+
}
227229

228230
return $this;
229231
}
@@ -236,9 +238,11 @@ public function prependToChain($job)
236238
*/
237239
public function appendToChain($job)
238240
{
239-
$jobs = ChainedBatch::prepareNestedBatches(new Collection([$job]));
241+
$jobs = ChainedBatch::prepareNestedBatches(Collection::wrap($job));
240242

241-
$this->chained = array_merge($this->chained, [$this->serializeJob($jobs->first())]);
243+
foreach ($jobs as $job) {
244+
$this->chained = array_merge($this->chained, [$this->serializeJob($job)]);
245+
}
242246

243247
return $this;
244248
}

0 commit comments

Comments
 (0)