By making use of this method if one job fails to process the whole sequence will fail to process hence making the flow optimal for processing subsequence tasks.
Laravel Bus Chain
To define the jobs you can define the code as follows.
<?php use App\Jobs\ProcessImage; use App\Jobs\OptimseImage; use App\Jobs\ReleaseImage; use Illuminate\Support\Facades\Bus; Bus::chain([ new ProcessImage, new OptimseImage, new ReleaseImage, ])->dispatch();
Passing Closure to Jobs Chain
To pass a closure to the jobs chain you can define your code like below.
<?php Bus::chain([ new ProcessImage, new OptimseImage, function () { Image::update(...); }, ])->dispatch();
Chain Connection and Queue in Laravel
To specify the connection and queue in the Jobs chain you can chain the method using the "onConnection" and "onQueue" and passing the value as the method parameter.
<?php Bus::chain([ new ProcessImage, new OptimseImage, new ReleaseImage, ])->onConnection('redis')->onQueue('podcasts')->dispatch();
<?php Bus::chain([ new ProcessImage, new OptimseImage, new ReleaseImage, ]) ->onConnection('redis') ->onQueue('podcasts') ->catch(function (Throwable $e) { // A job within the chain has failed... }) ->dispatch();
Leave a reply