introduction to delayed job

37
"Maybe we should have a talk on delayed_job" @subelsky

Upload: jonathan-julian

Post on 19-Jan-2015

5.074 views

Category:

Technology


1 download

DESCRIPTION

An introduction to the delayed_job gem.

TRANSCRIPT

Page 1: Introduction To Delayed Job

"Maybe we should have a talk on delayed_job"@subelsky

Page 2: Introduction To Delayed Job

An Introduction to delayed_job

@bmoreonrails2009-11-10

Page 3: Introduction To Delayed Job

I’m @jonathanjulian

Page 4: Introduction To Delayed Job

Why do we need background processing?

Page 5: Introduction To Delayed Job

User Experience

Page 6: Introduction To Delayed Job

Sending an email

Page 7: Introduction To Delayed Job

Resizing an image

Page 8: Introduction To Delayed Job

Updating a web service

Page 9: Introduction To Delayed Job

Geocoding

Page 10: Introduction To Delayed Job

Batch import

Page 11: Introduction To Delayed Job
Page 12: Introduction To Delayed Job

Delayed::Job

“Extracted from Shopify”

database-persisted queue

0..n runners

Page 13: Introduction To Delayed Job

tobi/delayed_job

Page 14: Introduction To Delayed Job

collectiveidea/delayed_job

Page 15: Introduction To Delayed Job

Setup

Page 16: Introduction To Delayed Job

gem

Page 17: Introduction To Delayed Job

The Queue

Page 18: Introduction To Delayed Job

One db migration

Page 19: Introduction To Delayed Job
Page 20: Introduction To Delayed Job

Let’s delay something

Page 21: Introduction To Delayed Job

Notifier.deliver_activation_instructions(self)

Page 22: Introduction To Delayed Job

Notifier.send_later(:deliver_activation_instructions,

self)

Page 23: Introduction To Delayed Job

Easy!

Page 24: Introduction To Delayed Job

class Notifier def deliver_activation_instructions(user) # ... end handle_asynchronously :deliver_activation_instructionsend

Page 25: Introduction To Delayed Job

Custom jobs

Page 26: Introduction To Delayed Job

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

Who runs the jobs?

Page 28: Introduction To Delayed Job
Page 29: Introduction To Delayed Job

Workers

Page 30: Introduction To Delayed Job

rake jobs:work # Start a delayed_job worker.

Page 31: Introduction To Delayed Job

script/delayed_job start

* collectiveidea/delayed_job only

Page 32: Introduction To Delayed Job

Production Deployment

Page 33: Introduction To Delayed Job

# play nice with Passengerrequire 'delayed/recipes'after "deploy:update_code", "delayed_job:stop"after "deploy:restart", "delayed_job:start"

Page 35: Introduction To Delayed Job

"I highly recommend DelayedJob to anyone whose site is not 50%

background work." @defunkt

Page 36: Introduction To Delayed Job

@jonathanjulianhttp://jonathanjulian.com/