The Big Three-Oh
Delayed Job turned 3 over the holidays. It’s been a long time coming but it finally happened. A huge thanks goes out to betamatt for his contributions and help in maintaining this project over the past year, as well as bernardelli for adding named queues. Thanks guys!
Changes
Here’s a quick rundown of the changes. You can see the full list on GitHub.
- New: Named queues [ bernardelli ]
- New: Job/Worker lifecycle callbacks [ betamatt ]
- Change:
daemonsis no longer a runtime dependency - Change: Active Record backend support is provided by a separate gem
- Change: Enqueue hook is called before jobs are saved so that they may be modified
- Fix: Problem deserializing models that use a custom primary key column
- Fix: Deserializing AR models when the object isn’t in the default scope
- Fix: Hooks not getting called when delay_jobs is false
DJ 3 introduces Resque-style named queues while still retaining DJ-style priority. The goal is to provide a system for grouping tasks to be worked by separate pools of workers.
Jobs can be assigned to a queue by setting the queue option:
object.delay(:queue => 'tracking').method
Delayed::Job.enqueue job, :queue => 'tracking'
handle_asynchronously :tweet_later, :queue => 'tweets'
If you’re using rake, you can work off those queues by setting the QUEUE or QUEUES environment variable. If you’re using daemons, set the --queue or --queues option.
# with rake
$ QUEUE=tracking rake jobs:work
$ QUEUES=mailers,tasks rake jobs:work
# with daemons
$ RAILS_ENV=production delayed_job --queue=tracking start
$ RAILS_ENV=production delayed_job --queues=mailers,tasks start
DJ 3 no longer has daemons as a runtime dependency. You’ll need to add gem 'daemons' to your Gemfile if you want to use script/delayed_job. Check the comments on the commit for further explanation.
As always, feedback and patches are welcomed. :)

Post a Comment