Sha256: 64b0bef9361b40cffb8a442e91de3e35f9b8665ab2a3a18c7c70d2cdab51143e

Contents?: true

Size: 954 Bytes

Versions: 8

Compression:

Stored size: 954 Bytes

Contents

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_UPID")
            require File.dirname(__FILE__) + "/scalers/heroku"
            Scaler::Heroku.new
          else
            require File.dirname(__FILE__) + "/scalers/local"
            Scaler::Local.new
          end
        end

        def scaler=(scaler)
          require File.dirname(__FILE__) + "/scalers/#{scaler.to_s}"
          @scaler = "Delayed::Workless::Scaler::#{scaler.to_s.camelize}".constantize.new
        end
      end
      
    end
    
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
workless-0.2.0 lib/workless/scaler.rb
workless-0.1.0 lib/workless/scaler.rb
workless-0.0.9 lib/workless/scaler.rb
workless-0.0.8 lib/workless/scaler.rb
workless-0.0.7 lib/workless/scaler.rb
workless-0.0.6 lib/workless/scaler.rb
workless-0.0.5 lib/workless/scaler.rb
workless-0.0.4 lib/workless/scaler.rb