Collective Idea

Collective Idea Logo

Brian Ryckbost

The Big Three-Oh

By Brian Ryckbost on January 04, 2012 in

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: daemons is 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. :)

By Brian Ryckbost on January 04, 2012 in

3 Comments

  1. ray

    ray June 06, 2012 http://www.grainmaster.net

    Hi Guys,
    Thanks for fork of delayed_job.
    Having a bit of trouble.
    Changed from Bj(no longer supported in Rail3) to Delayed_job but seems not to handle rails runner.

    lib/report_job.rb 
    class ReportJob < Struct.new(:prawn_script_name , :account_id ) 
    def perform 
    bundle exec rails runner “#{Rails.root}/jobs/#{prawn_script_name}.rb #{account_id}” 
    end
    Error in last_error field. 
    {undefined method `runner’ for #ReportJob:0xc28f080

    OUCH! …. will try Resque.
    Any chance it can take rails runner in def perform?
    rgs ray

  2. ray

    ray June 07, 2012 http://www.grainmaster.net

    Delayed_job and Prawn scripts:
    One suggestion is to use
    def perform
     load “#{Rails.root}/jobs/#{prawn_script_name}.rb”
    end
    which works 
    http://stackoverflow.com/questions/10930300/delayed-job-and-prawn-scripts

    BUT 
    i need to pass arguments to the Prawn pdf scripts to scope the data.
    (runner allows ARGs to be passed but Load does not)
    This is my next hurdle to overcome.
    rgs ray

  3. Chris Gaffney

    Chris Gaffney June 07, 2012

    Ray: You’ll have better luck at the delayed job google group (https://groups.google.com/forum/?fromgroups#!forum/delayed_job)

Post a Comment

Contact Us

Find us on Google Maps
Collective Idea
44 East 8th Street, Suite 410
Holland, Michigan 49423 USA 42.790334-86.105251

Follow us on the Interwebs

We are currently available for medium and long term projects. Please get in touch if we can be of service.