laravellaravel-5laravel-queuelaravel-jobs

how to put schedule task jobs in chain in laravel?


I am using laravel task scheduling inside it queue jobs or working i want to put these jobs in chain kernel.php

    $schedule->job(new \App\Jobs\FetchEmailAttachment)->dailyAt('16:15')->timezone('Australia/Melbourne');
    $schedule->job(new \App\Jobs\UploadFileFTP)->dailyAt('16:15')->timezone('Australia/Melbourne');
    $schedule->job(new \App\Jobs\SplitAttachment)->dailyAt('16:15')->timezone('Australia/Melbourne');           
    $schedule->job(new \App\Jobs\ResendAttachment)->dailyAt('16:15')->timezone('Australia/Melbourne');

I tried to use laravel withChain method but its not working .

I want to run these job in chain


Solution

  • Use call closure, to add a new callback to the $schedule and then within use withChain to dispatch chained jobs, starting with first one:

     $schedule->call(function(){
               \App\Jobs\FetchEmailAttachment::withChain([
                    new \App\Jobs\UploadFileFTP,
                    new \App\Jobs\SplitAttachment,
                    new \App\Jobs\ResendAttachment,             
                ])->dispatch();
     })
     ->dailyAt('16:15')
     ->timezone('Australia/Melbourne');