How do I separate workers into pools of jobs with delayed job + heroku? How do I separate workers into pools of jobs with delayed job + heroku? heroku heroku

How do I separate workers into pools of jobs with delayed job + heroku?


It's in the README for Delayed Job 3:

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, which may be scaled and controlled individually.

Jobs can be assigned to a queue by setting the queue option:

object.delay(:queue => 'tracking').methodDelayed::Job.enqueue job, :queue => 'tracking'handle_asynchronously :tweet_later, :queue => 'tweets'

script/delayed_job can be used to manage a background process which will start working off jobs.

To do so, add gem "daemons" to your Gemfile and make sure you’ve run rails generate delayed_job.

You can then do the following:

$ RAILS_ENV=production script/delayed_job start$ RAILS_ENV=production script/delayed_job stop# Runs two workers in separate processes.$ RAILS_ENV=production script/delayed_job -n 2 start$ RAILS_ENV=production script/delayed_job stop# Set the --queue or --queues option to work from a particular queue.$ RAILS_ENV=production script/delayed_job --queue=tracking start$ RAILS_ENV=production script/delayed_job --queues=mailers,tasks start

Work off queues by setting the QUEUE or QUEUES environment variable.

QUEUE=tracking rake jobs:workQUEUES=mailers,tasks rake jobs:work

On Heroku, In your procfile, create two entries:

worker1: QUEUE=tracking rake jobs:workworker2: QUEUES=mailers,tasks rake jobs:work

and scale them individually:

heroku ps:scale worker1=2 worker2=1 

etc


Original question asked about HireFire as well. At this time HireFire does not support named queues (see HireFire website) which makes auto-scaling difficult.