lostboy/workless — pull request #14 by bdotdub (2011-10-21 16:24:33+00:00)
Title: Update the way scalers are loaded

Add functionality to add user defined scalers.

From the main commit (https://github.com/bdotdub/workless/commit/20c19eb43f94b2dc14481bfbdc568bb0acd32295):

Change the way scalers are loaded

* Previously, the scaler needed to be defined and loaded from
within the workless gem. Therefore, if you wanted to implement
a new scaler, you'd have to fork and implement. Now, you can
defined a scaler by putting it in the Delayed::Workless::Scaler
module and you should be good to go
* How this works technically:
- The previous way was to require the scaler from within the gem
directory, and then instantiate a new instance of the scaler
- Now, the scalers only have class methods as "callbacks". Since
the scalers aren't holding content (ie. instance variables),
there's no need for the scalers to be instantiated
* For scalers that need to talk to heroku, you need to extend the
scaler to use Delayed::Workless::Scaler::HerokuClient
* Example scaler:

class Delayed::Workless::Scaler::SuperDuperRandom

extend Delayed::Workless::Scaler::HerokuClient

def self.up
client.set_workers(ENV['APP_NAME'], rand(24)
end

def self.down
client.set_workers(0)
end

end