No commit activity in last 3 years
No release in over 3 years
This gem scales your Heroku workers according to the number of pending Resque jobs. You can customize the scaling behavior of your workers, however you like.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

>= 0
>= 1.8
 Project Readme

Resque Heroku Autoscaler (RHA)

A Resque plugin. Requires Resque 1.8 and the Heroku-api gem.

This gem scales your Heroku workers according to the number of pending Resque jobs. The original idea comes from Daniel Huckstep's blog post on the topic

##Setup

In order for the scaling to work RHA needs to know your Heroku app's name, your Heroku user name and your Heroku password. Per default those are being read from the following environment variables:

  • HEROKU_APP
  • HEROKU_API_KEY

If you prefer you also can configure RHA using a config block. For example you might put the following into config/initialiazers/resque_heroku_autoscaler_setup.config

require 'resque/plugins/resque_heroku_autoscaler'

Resque::Plugins::HerokuAutoscaler.config do |c|
  c.heroku_app  = "my_app_#{Rails.env}"
  c.heroku_api_key = 'abdcef'
end

To use RHA in one of your jobs, just extend your job class with Resque::Plugins::HerokuAutoscaler.

For example:

require 'resque/plugins/resque_heroku_autoscaler'

class TestJob
  extend Resque::Plugins::HerokuAutoscaler

  @queue = :test

  def perform
   ...awesome stuff...
  end
end

When you add the job to your Resque queue, a new worker will be started if there isn't already one. If all jobs in the queue are processed the worker will be stopped again, keeping your costs low.

Per default RHA will only start a single worker, no matter how many jobs are pending. You can change this behavior in the config block as well:

require 'resque/plugins/resque_heroku_autoscaler'

Resque::Plugins::HerokuAutoscaler.config do |c|
  c.new_worker_count do |pending|
    (pending/5).ceil.to_i
  end
end

When calculating the new number of required workers the block given to new_worker_count will be called. Thus the example will result in starting one additional worker for every 5 pending jobs.

You might want to turn off scaling of your workers in development modus. You can do that by setting scaling_disabled to true in your init script:

if (Rails.env == 'development')
  Resque::Plugins::HerokuAutoscaler.config do |c|
    c.scaling_disabled = true
  end
end