最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Cron jobs when running multiple instances on the same DB

programmeradmin3浏览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?

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 badges
Add a comment  | 

1 Answer 1

Reset to default 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

发布评论

评论列表(0)

  1. 暂无评论