Reputation: 2215
Laravel 8 introduced Job Batching, which allows to execute jobs in batches and perform actions on batch completion and failure. When a job within batch fails, the catch
callback is executed and the whole batch is marked as "canceled" according to the documentation. In case you don't want the batch to cancel (on the first failure) you can append the method allowFailures()
while dispatching the batch:
$batch = Bus::batch([
// ...
])->then(function (Batch $batch) {
// All jobs completed successfully...
})->catch(function (Batch $batch, Throwable $e) {
// First batch job failure detected...
// TODO: call this for every failed job
})->allowFailures()->dispatch();
It works as expected, however I wonder whether it's possible to call catch
closure for every failed job? (at this case with allowFailures
)
Upvotes: 2
Views: 1174
Reputation: 39
You can use number of attemtps in Jobs for finding failed job
if ($this->attempts() > 1) {
// your code
}
Upvotes: 0