Mar 09, 2009 / rubyonrails ~ ruby
6 ways to run background jobs in Ruby (On Rails)

I was trying to find a neat way of running background jobs for a Rails app I'm working on.

I was rather pleased to find that this is well trodden ground. There are at least six solutions that can help me. Ah, the wonders of the code n' share Ruby community...

Here's the contenders I've found so far, for anyone who's interested.

And here's some things that might help with the whole "distributed work queue" problem too...

There's a nice slideshow that goes into pros/cons of these tools.

My needs are simple, so I'm keen to use something that runs of the box; I've no skill or time for crazy admin foo.

The favourites are:

I like background job because of it's simplicity, Bj just runs the ruby or bash scripts you tell it to. It's also durable and clusterable.

# /www_railsapp/app/controllers/email_controller.rb

def send_emails()
  Bj.submit "./script/runner ./jobs/send_digest_emails.rb"

# /www_railsapp/jobs/send_digest_emails.rb

site_updates = Activity.find_todays_activities
Emails.find(:all).each do |user|
    Postoffice.send_activity_email user, site_updates

But, if I wanted to do something on a regular basis (every night at 11pm) I might have to start dicking around with Cron jobs. So I wonder if delayed_job might be the one?

I'll post up what I settle on soon.

You may also like...