introduction to delayed job
DESCRIPTION
An introduction to the delayed_job gem.TRANSCRIPT
![Page 1: Introduction To Delayed Job](https://reader034.vdocuments.net/reader034/viewer/2022042518/54bd16884a795957558b4597/html5/thumbnails/1.jpg)
"Maybe we should have a talk on delayed_job"@subelsky
![Page 2: Introduction To Delayed Job](https://reader034.vdocuments.net/reader034/viewer/2022042518/54bd16884a795957558b4597/html5/thumbnails/2.jpg)
An Introduction to delayed_job
@bmoreonrails2009-11-10
![Page 3: Introduction To Delayed Job](https://reader034.vdocuments.net/reader034/viewer/2022042518/54bd16884a795957558b4597/html5/thumbnails/3.jpg)
I’m @jonathanjulian
![Page 4: Introduction To Delayed Job](https://reader034.vdocuments.net/reader034/viewer/2022042518/54bd16884a795957558b4597/html5/thumbnails/4.jpg)
Why do we need background processing?
![Page 5: Introduction To Delayed Job](https://reader034.vdocuments.net/reader034/viewer/2022042518/54bd16884a795957558b4597/html5/thumbnails/5.jpg)
User Experience
![Page 6: Introduction To Delayed Job](https://reader034.vdocuments.net/reader034/viewer/2022042518/54bd16884a795957558b4597/html5/thumbnails/6.jpg)
Sending an email
![Page 7: Introduction To Delayed Job](https://reader034.vdocuments.net/reader034/viewer/2022042518/54bd16884a795957558b4597/html5/thumbnails/7.jpg)
Resizing an image
![Page 8: Introduction To Delayed Job](https://reader034.vdocuments.net/reader034/viewer/2022042518/54bd16884a795957558b4597/html5/thumbnails/8.jpg)
Updating a web service
![Page 9: Introduction To Delayed Job](https://reader034.vdocuments.net/reader034/viewer/2022042518/54bd16884a795957558b4597/html5/thumbnails/9.jpg)
Geocoding
![Page 10: Introduction To Delayed Job](https://reader034.vdocuments.net/reader034/viewer/2022042518/54bd16884a795957558b4597/html5/thumbnails/10.jpg)
Batch import
![Page 11: Introduction To Delayed Job](https://reader034.vdocuments.net/reader034/viewer/2022042518/54bd16884a795957558b4597/html5/thumbnails/11.jpg)
![Page 12: Introduction To Delayed Job](https://reader034.vdocuments.net/reader034/viewer/2022042518/54bd16884a795957558b4597/html5/thumbnails/12.jpg)
Delayed::Job
“Extracted from Shopify”
database-persisted queue
0..n runners
![Page 13: Introduction To Delayed Job](https://reader034.vdocuments.net/reader034/viewer/2022042518/54bd16884a795957558b4597/html5/thumbnails/13.jpg)
tobi/delayed_job
![Page 14: Introduction To Delayed Job](https://reader034.vdocuments.net/reader034/viewer/2022042518/54bd16884a795957558b4597/html5/thumbnails/14.jpg)
collectiveidea/delayed_job
![Page 15: Introduction To Delayed Job](https://reader034.vdocuments.net/reader034/viewer/2022042518/54bd16884a795957558b4597/html5/thumbnails/15.jpg)
Setup
![Page 16: Introduction To Delayed Job](https://reader034.vdocuments.net/reader034/viewer/2022042518/54bd16884a795957558b4597/html5/thumbnails/16.jpg)
gem
![Page 17: Introduction To Delayed Job](https://reader034.vdocuments.net/reader034/viewer/2022042518/54bd16884a795957558b4597/html5/thumbnails/17.jpg)
The Queue
![Page 18: Introduction To Delayed Job](https://reader034.vdocuments.net/reader034/viewer/2022042518/54bd16884a795957558b4597/html5/thumbnails/18.jpg)
One db migration
![Page 19: Introduction To Delayed Job](https://reader034.vdocuments.net/reader034/viewer/2022042518/54bd16884a795957558b4597/html5/thumbnails/19.jpg)
![Page 20: Introduction To Delayed Job](https://reader034.vdocuments.net/reader034/viewer/2022042518/54bd16884a795957558b4597/html5/thumbnails/20.jpg)
Let’s delay something
![Page 21: Introduction To Delayed Job](https://reader034.vdocuments.net/reader034/viewer/2022042518/54bd16884a795957558b4597/html5/thumbnails/21.jpg)
Notifier.deliver_activation_instructions(self)
![Page 22: Introduction To Delayed Job](https://reader034.vdocuments.net/reader034/viewer/2022042518/54bd16884a795957558b4597/html5/thumbnails/22.jpg)
Notifier.send_later(:deliver_activation_instructions,
self)
![Page 23: Introduction To Delayed Job](https://reader034.vdocuments.net/reader034/viewer/2022042518/54bd16884a795957558b4597/html5/thumbnails/23.jpg)
Easy!
![Page 24: Introduction To Delayed Job](https://reader034.vdocuments.net/reader034/viewer/2022042518/54bd16884a795957558b4597/html5/thumbnails/24.jpg)
class Notifier def deliver_activation_instructions(user) # ... end handle_asynchronously :deliver_activation_instructionsend
![Page 25: Introduction To Delayed Job](https://reader034.vdocuments.net/reader034/viewer/2022042518/54bd16884a795957558b4597/html5/thumbnails/25.jpg)
Custom jobs
![Page 26: Introduction To Delayed Job](https://reader034.vdocuments.net/reader034/viewer/2022042518/54bd16884a795957558b4597/html5/thumbnails/26.jpg)
class LongRunningJob < Struct.new(:id) def perform # do some crazy long calculations endend
Delayed::Job.enqueue LongRunningJob.new(42)
![Page 27: Introduction To Delayed Job](https://reader034.vdocuments.net/reader034/viewer/2022042518/54bd16884a795957558b4597/html5/thumbnails/27.jpg)
Who runs the jobs?
![Page 28: Introduction To Delayed Job](https://reader034.vdocuments.net/reader034/viewer/2022042518/54bd16884a795957558b4597/html5/thumbnails/28.jpg)
![Page 29: Introduction To Delayed Job](https://reader034.vdocuments.net/reader034/viewer/2022042518/54bd16884a795957558b4597/html5/thumbnails/29.jpg)
Workers
![Page 30: Introduction To Delayed Job](https://reader034.vdocuments.net/reader034/viewer/2022042518/54bd16884a795957558b4597/html5/thumbnails/30.jpg)
rake jobs:work # Start a delayed_job worker.
![Page 31: Introduction To Delayed Job](https://reader034.vdocuments.net/reader034/viewer/2022042518/54bd16884a795957558b4597/html5/thumbnails/31.jpg)
script/delayed_job start
* collectiveidea/delayed_job only
![Page 32: Introduction To Delayed Job](https://reader034.vdocuments.net/reader034/viewer/2022042518/54bd16884a795957558b4597/html5/thumbnails/32.jpg)
Production Deployment
![Page 33: Introduction To Delayed Job](https://reader034.vdocuments.net/reader034/viewer/2022042518/54bd16884a795957558b4597/html5/thumbnails/33.jpg)
# play nice with Passengerrequire 'delayed/recipes'after "deploy:update_code", "delayed_job:stop"after "deploy:restart", "delayed_job:start"
![Page 34: Introduction To Delayed Job](https://reader034.vdocuments.net/reader034/viewer/2022042518/54bd16884a795957558b4597/html5/thumbnails/34.jpg)
http://railstips.org/2008/11/19/delayed-
gratification-with-rails
![Page 35: Introduction To Delayed Job](https://reader034.vdocuments.net/reader034/viewer/2022042518/54bd16884a795957558b4597/html5/thumbnails/35.jpg)
"I highly recommend DelayedJob to anyone whose site is not 50%
background work." @defunkt
![Page 36: Introduction To Delayed Job](https://reader034.vdocuments.net/reader034/viewer/2022042518/54bd16884a795957558b4597/html5/thumbnails/36.jpg)
@jonathanjulianhttp://jonathanjulian.com/
![Page 37: Introduction To Delayed Job](https://reader034.vdocuments.net/reader034/viewer/2022042518/54bd16884a795957558b4597/html5/thumbnails/37.jpg)
Photo Attributions
• http://www.flickr.com/photos/aloshbennett/540105576/
• http://www.flickr.com/photos/gyrus/132436475/
• http://www.flickr.com/photos/gavatron/866650954/