If I scheduled a CPU-intensive job via a cron scheduled event, how do I go about stopping it or cancelling the job while it is currently running?
2 Answers
Removing / un-scheduling obsolete cron jobs can be achieved using this code snippet.
add_action("init", "remove_cron_job");
function remove_cron_job() {
wp_clear_scheduled_hook("my_schedule_hook");
}
Change the my_schedule_hook to cron’s hook name and add the code in your theme’s function.php file.
-
2
-
Also wondering if this is possible (stopping the currently running cron) Mar 9, 2017 at 23:56
You can delete scheduled cron jobs via a SSH command line. First, take a look at all your active and scheduled cron jobs by doing this command:
$ wp cron event list
Then you can delete any of the cron jobs by using their hook name. Let's say you have six jobs whose hook name is "crontrol_cron_job". You would run this command:
$ wp cron event delete crontrol_cron_job
You'll get a result of something like:
Deleted 6 instances of the cron event 'crontrol_cron_job'.