问题与鲁弗斯,调度,当我们有多个EC2实例 [英] Issue with rufus-scheduler when we have multiple EC2 instances
问题描述
我已经部署的Rails应用上的两个EC2实例。我已安排的作业与鲁弗斯,调度运行,每24小时发送一些电子邮件。
I have deployed rails app on two EC2 instances. I have scheduled on Job with rufus-scheduler to run every 24 hours to send some emails.
不过,调度器上的两个实例独立运行。
But scheduler is running separately on two instances.
我需要的只有一个实例运行调度。所以,你能帮这个问题?
I need run scheduler on only one instance. So can you please help with this issue?
感谢
推荐答案
让我们假设你遵循的 https://github.com/jmettraux/rufus-scheduler#so-rails
您可以修改初始化以这种方式:
You could modify the initializer in this way:
#
# config/initializers/scheduler.rb
require 'rufus-scheduler'
s = Rufus::Scheduler.singleton
unless File.exist?(File.dirname(__FILE__) + '/../../no_scheduling')
s.every '1m' do
Rails.logger.info "hello, it's #{Time.now}"
end
end
然后,在你不想来安排实例的Rails的根,只需触摸no_scheduling文件,然后启动你的Rails。着有no_scheduling文件的情况下,也不会安排。
Then in the Rails root of the instance you don't want to schedule, simply touch the no_scheduling file, then start your Rails. The instances with a "no_scheduling" file will not schedule.
练习1:增强的上方,使得它甚至不实例化调度,如果no_scheduling是present初始化
Exercise 1: enhance the initializer above so that it doesn't even instantiate the scheduler if no_scheduling is present.
练习2:通过IP检查替换文件检查,这样只对指定的IP调度导轨安装
Exercise 2: replace the file check by an IP check so that only the rails setup on a given IP schedules.
这篇关于问题与鲁弗斯,调度,当我们有多个EC2实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!