Sha256: dc32e46c8ecc31ca530d42be947e392c51a357d3f5e8756c6c036402df295070

Contents?: true

Size: 1.19 KB

Versions: 1

Compression:

Stored size: 1.19 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
        unless base.to_s =~ /ActiveRecord/
          base.class_eval do
            after_destroy "self.class.scaler.down"
            after_create "self.class.scaler.up"
            after_update "self.class.scaler.down", :unless => Proc.new {|r| r.failed_at.nil? }
          end
        else
          base.class_eval do
            after_commit "self.class.scaler.down", :on => :destroy
            after_commit "self.class.scaler.up", :on => :create
            after_commit "self.class.scaler.down", :on => :update, :unless => Proc.new {|r| r.failed_at.nil? }
          end
        end

      end

      module ClassMethods
        def scaler
          @scaler ||= if ENV.include?("HEROKU_API_KEY")
            Scaler::HerokuCedar
          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

1 entries across 1 versions & 1 rubygems

Version Path
workless-1.1.3 lib/workless/scaler.rb