"Maybe we should have a talk on delayed_job"
                @subelsky
An Introduction to
   delayed_job
     @bmoreonrails
      2009-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_ins...
Custom jobs
class LongRunningJob < Struct.new(:id)
  def perform
    # do some crazy long calculations
  end
end

Delayed::Job.enqueue...
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 Passenger
require 'delayed/recipes'
after "deploy:update_code", "delayed_job:stop"
after "deploy:restart"...
http://railstips.org/
 2008/11/19/delayed-
gratification-with-rails
"I highly recommend
DelayedJob to anyone
whose site is not 50%
 background work."
      @defunkt
@jonathanjulian
http://jonathanjulian.com/
Photo Attributions

•   http://www.flickr.com/photos/aloshbennett/540105576/

•   http://www.flickr.com/photos/gyrus/13243...
Introduction To Delayed Job
Introduction To Delayed Job
Introduction To Delayed Job
Upcoming SlideShare
Loading in …5
×

Introduction To Delayed Job

5,862 views

Published on

An introduction to the delayed_job gem.

Published in: Technology, Business
0 Comments
4 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
5,862
On SlideShare
0
From Embeds
0
Number of Embeds
660
Actions
Shares
0
Downloads
16
Comments
0
Likes
4
Embeds 0
No embeds

No notes for slide

Introduction To Delayed Job

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

×