Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stop a Laravel scheduled command once started?

I have set up a scheduled command for a laravel 5.1 project.

It works, the command has started, but rather foolishly I didn't think about how I might stop it.

Normally you wouldn't want to stop it, but the command is inserting nearly half a million rows into a database table, and I only really wanted to make sure I could start it without being logged into the server.

I will obviously need to run it at some point but not right now, so is there a way to stop the command mid-flow?

like image 457
John Halsey Avatar asked Aug 10 '15 12:08

John Halsey


People also ask

How do I stop a scheduled task in Laravel?

By default, scheduled tasks will be run even if the previous instance of the task is still running. To prevent this, you may use the withoutOverlapping method: $schedule->command('emails:send')->withoutOverlapping(); In this example, the emails:send Artisan command will be run every minute if it is not already running.

How do I know if a cron job is running in Laravel?

Run Schedule Command for a test To check if schedule commands have been constructed successfully, run this command. After that, go to the logs folder inside the storage directory, open the Laravel. php cron job file, and check it. Note: You can use this command when you want a Laravel scheduler without a cron job.

How do I stop Laravel artisan serve?

To execute php artisan serve stop simply goto your commnad line where your server is running and press ctrl+c. It will stop your server.

How do I schedule a cron job in Laravel?

Now to activate the scheduled jobs, run the Cron command. Go to your application from the Applications tab, and then to the Cron Jobs Manager. When done, make sure to save changes. That's it!


1 Answers

This worked for me after I found a fault in my scheduled code and it was going to keep running for a really long time. SSH into the server.

ps -fe | grep artisan

then kill PID (PID being the number of the process). Killing the first two results worked for me.

Note: If you are using withoutOverlapping() the process will not start up again unless you change the ->name() to something unique.

like image 163
cbyte Avatar answered Sep 27 '22 20:09

cbyte