Implementation of the Rufus planner on rails 3

I have an application that works with Apache + Passenger in production. I am currently initializing the rufus scheduler in the initializer and registering jobs specified from db in this initializer. The apache / passenger path is that it creates several processes / instances of the application, which is why the scheduler receives initialization several times and plans to duplicate tasks.

What is the correct implementation of this, so that the scheduler is a singleton object?

+5
source share
1 answer

You probably want to implement Rufus Scheduler as a separate workflow outside your application.

Instead of putting it as an initializer, I would do the Rake task that ran it.

# Rakefile
desc "Starts the Scheduler worker"
task :scheduler do
  require 'path/to/your/scheduler/file'

  scheduler.join
end

Then just run rake schedulerto run it in the background.


Bonus: since your application now requires 2 processes side by side, use Foreman to control several processes of your application. You can do this by creating a file with the name Procfile:

# Procfile
web:       thin start -p 4242
scheduler: rake scheduler

Then launch the application using Foreman: (first make sure gem install foreman)

$ foreman start

This will cause both processes at the same time.

+4
source

All Articles