Ali
Ali

Reputation: 669

How Can I run a Command after another Command in Laravel

I have many Command class and they are running in background in my Laravel project. I have a scenario and I want to run one of the after another one.

        $schedule->command('mycommand:first')->cron("*/40 * * * *")->withoutOverlapping();
        $schedule->command('mycommand:two')->cron("*/40 * * * *")->withoutOverlapping();

they are running every 40 minutes. but I want to run Command two 10 minutes after Command first. How can I do that?

Upvotes: 0

Views: 604

Answers (1)

Adrian Kokot
Adrian Kokot

Reputation: 3226

If you just want to start command 10 minutes after the first command, you have to set properly cron command. So for your example it would be:

    $schedule->command('mycommand:first')->cron("*/40 * * * *")->withoutOverlapping();
    $schedule->command('mycommand:two')->cron("*/50 * * * *")->withoutOverlapping();

If you want to learn more about those cron settings you can try something like crontab.guru

If you want to run mycommand:two 10 minutes after mycommand:first finished, you have to probably edit mycommand:first to set some timeout and execution of mycommand:second at the end of the command.

Upvotes: 1

Related Questions