0

I have a user using my plugin that has multiple AWS instances hosting WP and pointing to the same database. One of the jobs of my plugins is to run a large number of small jobs.

I was thinking of using wp_schedule_single_event to schedule the jobs but I'm not sure how that will work with multiple instances. Each job will have unique parameters so there won't be any duplication.

Question: Will each instance try to run the same job or will WordPress be able to resolve this so that each job is only run once?

1

Question: Will each instance try to run the same job

Yes! If you have 5 machines running the same site, they'll all try to run the cron job. It'll be inconsistent, but if machine 1 triggers WP Cron and there's an event ready to run, and machine 2 triggers WP Cron, then machine 2 will also see that event if the timing is right and attempt to process it.

or will WordPress be able to resolve this so that each job is only run once?

Nope, it can't. You can try adding a lock of sorts, but it can't fix the problem, only prevent it in some scenarios


What you really need is to disable WP Cron in your config and run it via a system level cron job on a single machine. Or better yet, install a cron service such as cavalcade

1
  • That's what I suspected, thanks for the confirmation! – miked Sep 25 '20 at 8:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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