introduction to delayed job
DESCRIPTION
An introduction to the delayed_job gem.TRANSCRIPT
"Maybe we should have a talk on delayed_job"@subelsky
An Introduction to delayed_job
@bmoreonrails2009-11-10
I’m @jonathanjulian
Why do we need background processing?
User Experience
Sending an email
Resizing an image
Updating a web service
Geocoding
Batch import
Delayed::Job
“Extracted from Shopify”
database-persisted queue
0..n runners
tobi/delayed_job
collectiveidea/delayed_job
Setup
gem
The Queue
One db migration
Let’s delay something
Notifier.deliver_activation_instructions(self)
Notifier.send_later(:deliver_activation_instructions,
self)
Easy!
class Notifier def deliver_activation_instructions(user) # ... end handle_asynchronously :deliver_activation_instructionsend
Custom jobs
class LongRunningJob < Struct.new(:id) def perform # do some crazy long calculations endend
Delayed::Job.enqueue LongRunningJob.new(42)
Who runs the jobs?
Workers
rake jobs:work # Start a delayed_job worker.
script/delayed_job start
* collectiveidea/delayed_job only
Production Deployment
# play nice with Passengerrequire 'delayed/recipes'after "deploy:update_code", "delayed_job:stop"after "deploy:restart", "delayed_job:start"
http://railstips.org/2008/11/19/delayed-
gratification-with-rails
"I highly recommend DelayedJob to anyone whose site is not 50%
background work." @defunkt
@jonathanjulianhttp://jonathanjulian.com/
Photo Attributions
• http://www.flickr.com/photos/aloshbennett/540105576/
• http://www.flickr.com/photos/gyrus/132436475/
• http://www.flickr.com/photos/gavatron/866650954/