0

I am trying to chaing 4 commands one after another Example:

  $schedule->command('test1')->everyMinute()->onSuccess(function () use($schedule){
            $schedule->call('test2')->onSuccess(function () use($schedule){
                $schedule->call('test3')->onSuccess(function () use($schedule){
                   $schedule->call('test4');
                });
            });
        });

But Only the first command gets executed. Even if i use command instead of call inside the closures it does not work. any help is appreciated.

Sameer Shaikh
  • 7,564
  • 2
  • 17
  • 32
  • 1
    Why are you calling the `$scheduler` when you should refer to the Kernel, using `$this->call()` instead of `$schedule`? I think it does not run, because the scheduler needs to have instruction on when to run the command exactly. – Eric Landheer Jul 09 '21 at 08:38
  • @EricLandheer $this->call() I can't chain it further as there are 4 commands which need to run one after another – Sameer Shaikh Jul 09 '21 at 09:29
  • Look at this question, Explains how to call one command from another. https://stackoverflow.com/questions/61872499/custom-artisan-command-to-execute-multiple-commands/61872714 – Malkhazi Dartsmelidze Jul 09 '21 at 09:56

1 Answers1

1

You should refer to the Kernel using $this instead of passing the scheduler. The scheduler expects you to specify the frequency options. With the Kernel you can use the $this->call() function to run additional commands. Unfortunately, call() does not have hooks like onSuccess.

Instead, if you want to chain more than one command onSuccess() you should consider calling the command from another command.

Eric Landheer
  • 2,033
  • 1
  • 11
  • 25