在多个节点上运行rufus Scheduler问题?

Aut*_*act 0 ruby rufus-scheduler ruby-on-rails-3

在Rails 3应用程序中运行rufus-scheduler不会出现任何问题。

但是由于我的应用程序在节点集群app1.myapp.com-app2.myapp.com中运行,因此rufus-scheduler运行作业app(N)次。

如何使其只能在一台服务器上运行?

jme*_*aux 5

您是否想到过这种幼稚的解决方案:

# at initialization

if `hostname -f` == 'app1.myapp.com'
  $scheduler = Rufus::Scheduler.start_new
  $scheduler.every '5s' do
    puts "hello world"
  end
else
  # we're on another host, do not schedule anything
  $scheduler = nil
end
Run Code Online (Sandbox Code Playgroud)