Skip to content
Merged
Show file tree
Hide file tree
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
30 changes: 23 additions & 7 deletions src/Illuminate/Bus/Batch.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Illuminate\Contracts\Queue\Factory as QueueFactory;
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Queue\CallQueuedClosure;
use Illuminate\Queue\SyncQueue;
use Illuminate\Support\Arr;
use Illuminate\Support\Collection;
use JsonSerializable;
Expand Down Expand Up @@ -184,15 +185,30 @@ public function add($jobs)
return $job;
});

$this->repository->transaction(function () use ($jobs, $count) {
$queueConnection = $this->queue->connection($this->options['connection'] ?? null);

if ($queueConnection instanceof SyncQueue) {
$this->repository->incrementTotalJobs($this->id, $count);

$this->queue->connection($this->options['connection'] ?? null)->bulk(
$jobs->all(),
$data = '',
$this->options['queue'] ?? null
);
});
try {
$queueConnection->bulk(
$jobs->all(),
$data = '',
$this->options['queue'] ?? null
);
} catch (Throwable $e) {
}
} else {
$this->repository->transaction(function () use ($jobs, $count, $queueConnection) {
$this->repository->incrementTotalJobs($this->id, $count);

$queueConnection->bulk(
$jobs->all(),
$data = '',
$this->options['queue'] ?? null
);
});
}

return $this->fresh();
}
Expand Down
18 changes: 18 additions & 0 deletions tests/Integration/Queue/JobChainingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,24 @@ public function testChainBatchFailureNotAllowed()
$this->assertEquals(['batch failed', 'chain failed'], JobRunRecorder::$failures);
}

public function testChainBatchFailureNotAllowedOnSyncDoesNotDuplicateChainCatch()
{
config(['queue.default' => 'sync']);

JobRunRecorder::reset();

Bus::chain([
new JobChainingNamedTestJob('c1'),
Bus::batch([
new JobChainingTestFailingBatchedJob('fb-sync'),
])->allowFailures(false)->catch(fn () => JobRunRecorder::recordFailure('batch failed')),
new JobChainingNamedTestJob('c2'),
])->catch(fn () => JobRunRecorder::recordFailure('chain failed'))->dispatch();

$this->assertEquals(['batch failed', 'chain failed'], JobRunRecorder::$failures);
$this->assertSame(1, collect(JobRunRecorder::$failures)->filter(fn ($m) => $m === 'chain failed')->count());
}

public function testChainConditionable()
{
$chain = Bus::chain([])
Expand Down