GithubHelp home page GithubHelp logo

resque-heroku-scaling-canary's Introduction

resque-heroku-scaling-canary

This gem defines a Resque plugin that allows you to automatically scale up the number of workers running on Heroku and then automatically scale them down once no work is left to do. To use, extend the module from your job:

class MyJob
  extend Resque::Plugins::ScalingCanary
  
  def self.minimum_workers_needed
    10
  end

  def self.perform
    ...      
  end
end

Defining minimum_workers_needed like we did above is optional, but if you don't define it, it defaults to 1. ScalingCanary makes sure that when your job is enqueued there are at least this many workers working to service it.

Next, define the environment variables HEROKU_USER, HEROKU_PASSWORD, and HEROKU_APP with your heroku credentials and app name:

$ heroku config:add [email protected]
$ heroku config:add HEROKU_PASSWORD=5u93r53cr37
$ heroku config:add HEROKU_APP=awesome-app

When you enqueue your job, you'll see a new queue called "~scaling-canary" created with a single job in it. This job is the canary - its queue name is lexicographically after any other queue names you have, so it'll get processed last. When it runs, it looks around to see if any other jobs are being worked on or are awaiting workers on any queues. If any are, it requeues itself, but if everything's finished, it shuts down all workers.

There are a few other gems that allow you to automatically scale up the Heroku workers you use in response to your Resque load and then kill those workers automatically when the work is done: resque-heroku-autoscaler and hirefire are two notable examples. This gem is takes a dumber but more easily auditable approach than either of the above alternatives that's better suited to systems running a largish set of batch jobs that might spawn other Resque jobs. In particular, this gem is meant to work well with jobs using resque-multi-step, which enqueues finalization jobs from within Resque tasks in a way that sometimes confuses other auto-scaling gems.

This plugin works with Resque version 1.9 and above.

Installation:

gem install resque_heroku_scaling_canary

Configuration:

You can configure the following parameters:

  • heroku_user: defaults to the value of the environment variable HEROKU_USER
  • heroku_password: defaults to the value of the environment variable HEROKU_PASSWORD
  • heroku_app: defaults to the value of the environment variable HEROKU_APP
  • polling_interval: the polling interval, in seconds, that the canary should wait between checking the outstanding Resque jobs and working Resque workers. To be safe, the canary checks these values twice, waiting for polling_interval seconds in between, before shutting all workers down.
  • disable_scaling_if: called with a block, will evaluate the block and disable scaling entirely if it evaluates to true.

These values are easiest to configure in an initializer, for example, create the file config/initializers/resque_heroku_scaling_canary.rb and put something like the following in the file:

require 'resque_heroku_scaling_canary'

Resque::Plugins::ScalingCanary.config do |config|
  config.heroku_app = "myapp"
  config.polling_interval = 3
  config.disable_scaling_if{ Rails.env == 'development' }
end

resque-heroku-scaling-canary's People

Contributors

aaw avatar benhutton avatar

Stargazers

Koya Suzuki avatar  avatar Matthew Bass avatar Damien Bachet avatar Jerry Clinesmith avatar Pau Pérez Fabregat avatar Cory Preus avatar Justin Hileman avatar Evelyn Pai avatar Oscar Rendon avatar Robb Fitzsimmons avatar  avatar  avatar  avatar Michael D.W. Prendergast avatar Jonathan Vingiano avatar  avatar Michael Garriss avatar  avatar Graham Siener avatar Zeke Sikelianos avatar Andrew Nesbitt avatar Mike avatar

Watchers

Jay Swain avatar  avatar James Cloos avatar  avatar

resque-heroku-scaling-canary's Issues

Help testing against edge resque

Hey there!

I'm gearing up to work on Resque 2.0, and I'd like to coordinate better with plugin authors to make sure stuff doesn't break.

I'd like to know a few things:

  1. Can I do something to help get you testing against edge Resque?
  2. Are you monkey-patching anything in Resque currently? Can 2.0 expose an API to help you not have to do that any more?
  3. Do you need any help in bringing your plugin up-to-date with the latest Resque?

Thanks!

Related: https://github.com/defunkt/resque/issues/880

no such file to load -- resque_heroku_scaling_canary

/app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:240:in `require': no such file to load -- resque_heroku_scaling_canary (LoadError)

I'm getting that error when I try to start my server, with a config/initializers/resque_heroku_scaling_canary set up exactly like yours in the readme. I'm on Rails 3.1.1, loading the gem in my Gemfile. Any idea what's wrong?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.