BackgrounDRb
Background Job
Beanstalk
BackgroundFu
Spawn
Delayed Job
Sparrow
Workling
Workling
0% 50% 100%
Tool Method
Background Job Process’s stats
BackgroundFu Incremental
BackgrounDRb Ask workers
Workling DIY “return store”
Scheduling
BackgrounDRb
Delayed Job
Beanstalk
Process
Management
No Problem Hassle
Background Job
Everything else
Spawn
Examples
BackgrounDRb
# Lots of configuration
...
# Comments controller
def create
@comment = Comment.new(params[:comment])
if @comment.save
BEANSTALK.yput({:type => "comment", :id => @comment.id}) rescue nil
# Then redirect and return
end
end
Source: nubyonrails.com
Async Observer
# Some configuration
...
# Your code
class Person < ActiveRecord::Base
async_after_create do |person|
SiteStats.increment_members()
end
def befriend(other_person)
Friendship.async_send(:create, self, other_person)
end
end
Delayed Job
# Small config - db migration
# Stick in queue
Delayed::Job.enqueue NewsletterJob.new('lorem ipsum...',
Customers.find(:all).collect(&:email))
# Delayed job
BatchImporter.new(Shop.find(1)).send_later(:import_massive_csv, massive_csv)
# Running tasks
$ rake jobs:work <CTRL-C to cancel>
Background Job
# Command line
$ Bj.submit "./jobs/background_job_to_run"
# Within Rails
def upload_to_s3
Bj.submit "./script/runner ./jobs/s3_uploader.rb #{self.id}"
end
Source: slackworks.com
1
Background Job
Two-line installation
Zero configuration
No job-code constraints
Automatic* process management
Durable, prioritised, taggable jobs
Comprehensive job results
Clustering
* Manual if you want
Feed my spaniel
Buy my PeepCode PDF
Photo Credits:
1. BBC
2. Forever in Song (CD cover)
3. Me
4. Me
My Photos’ Licence:
Creative Commons Attribution-Noncommercial-No Derivative Works 2.0
UK: England & Wales Licence
Text’s Licence:
Creative Commons Attribution-Share Alike 2.0 UK: England & Wales Licence