Multiple RailsCron Instances

Posted 07/06/2006 by dnaffis 0 CommentsAdd Your Comment

Just to follow up on my last post about using RailsCron.

If you want to run multiple instances of RailsCron you need to change the startup tasks in the rake file.

In my particular case I wanted a separate instance running for each of the sites that required it. I’m running them all as Daemons so I changed the cron_start target in my rake file.

From the root of of your app edit the rake file:
vi vendor/plugins/trunk/tasks/startup.rake
Change
desc "Starts RailsCron as a daemon"
task :cron_start do
  if `#{sudo "ps x | grep RailsCron | grep -v grep"}`.strip.blank?
    mode = ENV['RAILS_ENV'] || "development"
    puts `#{sudo "nohup ruby script/runner -e #{mode} \"RailsCron.start\" > /dev/null 2>&1 &"}`
  else
    puts "RailsCron already started"
  end
end
To the following:
desc "Starts RailsCron as a daemon"
task :cron_start do
    mode = ENV['RAILS_ENV'] || "development"
    puts `#{sudo "nohup ruby script/runner -e #{mode} \"RailsCron.start\" > /dev/null 2>&1 &"}`
end

This removes the check for an existing RailsCron process and lets you start a new one. Be careful.

Now you can run rake cron_start from the root of each app that requires a RailsCron instance. Running rake cron_stop will stop all the RailsCron processes so you’ll have to start each one up again.

Leave a Reply

Dave is the cofounder of Intridea and leads Intridea's product development efforts.

Before Intridea, Dave spent years at both AOL and IMAKE and received a Masters in Systems Engineering from the University of Virginia.