Update the way scalers are loaded #14

Closed
wants to merge 16 commits into
from

Conversation

Projects
None yet
2 participants
Contributor

bdotdub commented Oct 21, 2011

Add functionality to add user defined scalers.

From the main commit (bdotdub/workless@20c19eb):

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

bdotdub added some commits Apr 8, 2011

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
Owner

lostboy commented Feb 18, 2012

Thanks loads for these suggestions. I've cherry picked your loading commit and mixed it with a few others. Notice I've left out your log scalers but now I'm loading scalers like you suggested I should be easy to incorporate them in a separate gem. Also note I've released v1.0.1 of the gem which has dj v3 support and rails 2.3, 3.0, 3.1 and 3.2 compatibility. Let me know how you get on with it.

@lostboy lostboy closed this Feb 18, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment