Sha256: f537d8c82c1aa548e16189c7366d1705e15a3786cf94ba6cd6fa76a14c4b440b

Contents?: true

Size: 1.11 KB

Versions: 1

Compression:

Stored size: 1.11 KB

Contents

require 'delayed_job'

module Delayed
  module Workless
    module Scaler
  
      class Base
        def self.jobs
          Delayed::Job.all(:conditions => { :failed_at => nil })
        end

        def self.scale_info= info
          @@scale_info = info
        end

        def self.num_workers_cache
          Rails.cache.read("WORKLESS_NUM_WORKERS") || 0
        end

        def self.num_workers_cache= num
          Rails.cache.write("WORKLESS_NUM_WORKERS", num)
        end
        
        def self.calculate_num_workers
          if num_workers.class == Fixnum
            @@scale_info ||= {
              0 => 1,
              100 => 2,
              500 => 3,
              1000 => 4
            }
            scale_key = @@scale_info.keys.reverse.select{|v| v < num_workers }.first
            if scale_key.nil?
              return 0
            else
              return @@scale_info[scale_key]
            end
          end
        end
      end

      module HerokuClient

        def client
          @client ||= ::Heroku::Client.new(ENV['HEROKU_USER'], ENV['HEROKU_PASSWORD'])
        end

      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rcarvalho-workless-1.0.2.12 lib/workless/scalers/base.rb