wp_schedule_single_event to run a function in the background immediately when a logged in user visits the dashboard page. The problem I'm having is that the time between triggering and the function actually running varies between a few seconds and 5 minutes.
I'm debugging by emailing myself as soon as I call
wp_schedule_single_event, and then in the function that is called. I know the event is scheduled immediately because I get the email quickly,
_transient_doing_cron is created in the
wp_options table, and the name of my action is added to
wp_options while it needs to be run.
My function runs fairly quickly and is done in less than 10 seconds. It's as if wordpress is running other crons before it, but I've tested this multiple times only a few minutes apart, so I can't always be getting an hourly cron that needs to be run. Can I prioritize my event to be run first? What else could be happening?