How to avoid Rufus scheduler being called as many times as there are no.of dynos?

谁说胖子不能爱 提交于 2019-12-08 11:06:57

问题


I am running a rails app in Heroku where I use Rufus Scheduler.

My app uses more than one dyno and the scheduler is running on each dyno rather than just one, so my scheduled events are firing multiple times (once for each dyno).

How can I avoid this?


回答1:


You should add a new process type in your Procfile that runs your Rufus scheduler process:

web: unicorn -c app/config/unicorn.rb ... # Your existing web dyno process
scheduler: rake rufus:scheduler # Add rake task for rufus scheduler process

You can then use heroku ps:scale to set one scheduler dyno and N web dynos.

EDIT

You have a Rails application which currently contains your rufus scheduler. When you deploy that application to Heroku, your Rails application code and required libraries are installed on each dyno (via one or more buildpacks). The dyno is a virtual machine that runs a process within your application.

By default, you have a dyno that runs a Rails web app server. If you add a second type of dyno, it will have the same codebase and libraries, but run a different process. In this case, that second process will be your Rufus scheduler process.



来源:https://stackoverflow.com/questions/21432850/how-to-avoid-rufus-scheduler-being-called-as-many-times-as-there-are-no-of-dynos

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!