Closed calebsmithdev closed 1 year ago
@Failcookie accidentally published the same link twice, the second link in his issue was intended to link to this line
I too have this issue. When I attempted handle_cron_healthcheck()
I finally got a task to fire successfully, but the server throws a 500.
Not sure if it's relevant here - however it seems that you can get issues with the heartbeat getting called in certain cases:
If your job classes get instantiated after the cron_schedules filter has fired [In which case the frequency doesn't get registered so the queueing of the healthcheck fails]
You dispatch your queue before the cron_schedules filter has fired [In which case the frequency hasn't been registered so the queueing of the healthcheck fails]
You don't instantiate the job classes on every request [for example you only instantiate them on is_admin(), or ! is_admin()]. In which case your class might not exist when cron fires.
I've hit all three of these on a project - although it's legacy code and is a bit of a rats nest of timing and dependencies so some of the above may be down to that in part. May help you though!
If your job classes get instantiated after the cron_schedules filter has fired [In which case the frequency doesn't get registered so the queueing of the healthcheck fails]
@leewillis77 After multiple hours of trial and error, this part of your comment finally helped me fix my issue. I was instantiating my background-process-class only when the user clicked a specific button in the WP Admin UI and, as it turns out, this was way too late. Moving the instantiation to the "plugins_loaded" hook solved my issue - thank you very much! 🎉
Closing ancient issue. :smile:
I've been having some issues with the Background process calling handle and activating the cron schedules needed for the fallback. Right now, I am utilizing something I saw in WooCommerce to force a healthcheck, which will start the handle process. I have also hooked that into the heartbeat function to continue polling for background processes, in the event the original timesout. This code starts the process, and this code is where I declare the handle_cron_healthcheck().
Is there a better way to make sure the background process has started? I want this to be pretty painless, from a user perspective, but I also want to make sure I understand what I am doing!
Really appreciate the help and for creating this awesome batch of code! I was really bummed when I moved from a Laravel project to a WP project and lost my queue process.