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?
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?
Share Improve this question asked Sep 24, 2020 at 14:10 mikedavies-devmikedavies-dev 979 bronze badges1 Answer
Reset to default 1Question: 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