Search code examples
rubyruby-on-rails-3rufus-scheduler

Running rufus scheduler on multiple nodes problem?


Running rufus-scheduler in a Rails 3 app without any problem.

But since my app is running in cluster of nodes, app1.myapp.com - app2.myapp.com, the rufus-scheduler is running the job app(N) times.

How can I make it run only on one server?


Solution

  • Have you thought of this naive solution:

    # 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
    

    ?