Sha256: bee01c8e2fbab643471ac55d63b42fdb16c417a5a39edaee1a746b5e38fe5155

Contents?: true

Size: 1.1 KB

Versions: 20

Compression:

Stored size: 1.1 KB

Contents

require 'workless/scalers/heroku'
require 'workless/scalers/heroku_cedar'
require 'workless/scalers/local'
require 'workless/scalers/null'

module Delayed
  module Workless 
    module Scaler
    
      def self.included(base)
        base.send :extend, ClassMethods
        base.class_eval do
          after_destroy "self.class.scaler.down"
          before_create "self.class.scaler.up"
          after_update "self.class.scaler.down", :unless => Proc.new {|r| r.failed_at.nil? }
        end
        
      end
      
      module ClassMethods
        def scaler
          @scaler ||= if ENV.include?("HEROKU_USER")
            client = ::Heroku::Client.new(ENV['HEROKU_USER'], ENV['HEROKU_PASSWORD'])
            case client.info(ENV["APP_NAME"])[:stack]
            when "cedar"
              Scaler::HerokuCedar
            else  
              Scaler::Heroku
            end
          else
            Scaler::Local
          end
        end

        def scaler=(scaler)
          @scaler = "Delayed::Workless::Scaler::#{scaler.to_s.camelize}".constantize
        end
        
      end
      
    end
    
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
rcarvalho-workless-1.0.2.21 lib/workless/scaler.rb
rcarvalho-workless-1.0.2.20 lib/workless/scaler.rb
rcarvalho-workless-1.0.2.19 lib/workless/scaler.rb
rcarvalho-workless-1.0.2.18 lib/workless/scaler.rb
rcarvalho-workless-1.0.2.17 lib/workless/scaler.rb
rcarvalho-workless-1.0.2.16 lib/workless/scaler.rb
rcarvalho-workless-1.0.2.15 lib/workless/scaler.rb
rcarvalho-workless-1.0.2.14 lib/workless/scaler.rb
rcarvalho-workless-1.0.2.13 lib/workless/scaler.rb
rcarvalho-workless-1.0.2.12 lib/workless/scaler.rb
rcarvalho-workless-1.0.2.11 lib/workless/scaler.rb
rcarvalho-workless-1.0.2.10 lib/workless/scaler.rb
rcarvalho-workless-1.0.2.9 lib/workless/scaler.rb
rcarvalho-workless-1.0.2.8 lib/workless/scaler.rb
rcarvalho-workless-1.0.2.7 lib/workless/scaler.rb
rcarvalho-workless-1.0.2.5 lib/workless/scaler.rb
rcarvalho-workless-1.0.2.4 lib/workless/scaler.rb
rcarvalho-workless-1.0.2.3 lib/workless/scaler.rb
rcarvalho-workless-1.0.2.2 lib/workless/scaler.rb
rcarvalho-workless-1.0.2.1 lib/workless/scaler.rb