1

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?

1
  • Is this a one-time thing or would you like to be able to cancel a cron event from somewhere on a regular basis, perhaps from another PHP script?
    – kovshenin
    Sep 4, 2015 at 11:28

2 Answers 2

2

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
  • 2
    but this won't stop the job that's currently running. Sep 5, 2015 at 7:54
  • Also wondering if this is possible (stopping the currently running cron)
    – atwellpub
    Mar 9, 2017 at 23:56
1

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'.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.