wecler's avatar

Schedule executing scheduled command in after or onSuccess

Hello there, I've faced an issue today with the Laravel Scheduler. I'm using version 6.3.5 (Lumen but that doesn't matter as its the same implementation).

I'm trying to make cronjobs that will be executed in a special order.

For example I've got two commands: CommandA, CommandB.

I'll start with CommandA.

$schedule->command('commandA')->everyMinute()->runInBackground()->withoutOverlapping();

That is working fine when I'm using php artisan schedule:run in the cmd.

After adding onSuccess (or after) to the schedule command before

$schedule->command('commandA')
         ->everyMinute()->runInBackground()->withoutOverlapping()
         ->onSuccess(function() use ($schedule) {
    $schedule->command('commandB')->runInBackground()->withoutOverlapping();
 });

CommandA will be executed while CommandB not.

I've registered both Commands in Kernel.php's array. Both methods can be used via php artisan. (php artisan commandA or php artisan commandB).

Any ideas how can I make it work? (I've seen Job Chaining but I'm asking myself if it can be done like this.)

Thanks in advance.

0 likes
0 replies

Please or to participate in this conversation.