Mhluzi Bhaka
Mhluzi Bhaka

Reputation: 1392

How to undo or stop php artisan schedule:run

This is in my dev environment for Laravel 5.3

I am testing out scheduled emails and ran:

php artisan schedule:run

This worked fine and is sending the emails as expected.

However I actually want this in the crontab file:

 * * * * * php /home/test/website/artisan schedule:run >> /dev/null 2>&1

Since I added that line in the crontab file I was getting two emails sent out. I removed the line so am now only getting one email.

But now I want to reverse/undo/stop/kill that php artisan schedule:run so that I can control the schedule from the crontab file.

I saw this article: Stop a Laravel scheduled command once started?

but the accepted answer ( ps -fe | grep artisan and kill PID ) for that doesn't work for me as I get the message:

kill: (PID) - No such process

Every time I run

ps -fe | grep artisan 

it seems to have a different PID - not sure what I am doing wrong in this.

I have also halted my vagrant box but that didn't seem to have any effect.

Any suggestions would be great!


UPDATE: Just in case future me happens to have the same issue and stumbles on this SO post again - I have not been able to solve this issue and have decided it is no longer worth putting any more time into solving it - will just live with it for now. By taking that line out of the crontab I am only getting one email so all good for now.

Upvotes: 6

Views: 19728

Answers (3)

ankith vishwakarma
ankith vishwakarma

Reputation: 104

You can create an artisan command like

  1. custom_schedule:process {type} which will store the type i.e reverse/undo/stop/kill in a schedule file in storage
  2. custom_schedule:run which will access the schedule file in storage to get the type and then run the Artisan::command('schedule:run') accordingly

Then change the crontab to * * * * * php /home/test/website/artisan custom_schedule:run >> /dev/null 2>&1

Upvotes: 3

夏期劇場
夏期劇場

Reputation: 18337

kill: (PID) - No such process

I have also halted my vagrant box but that didn't seem to have any effect.

Have you checked inside your host machine? Because this looks like you've been running the both or either of artisan and crontab inside your host machine, instead of inside the vagrant box.

Upvotes: 1

Davide Castronovo
Davide Castronovo

Reputation: 1396

Have you tried this in your code? withoutOverlapping() In order to prevent any overlapping.

$schedule->command('emails:send')->withoutOverlapping()

Upvotes: 6

Related Questions