Sha256: dc504633117105dd5c4e4441ca0f3993c2205dc66ffe430fa463a9db37f7661d

Contents?: true

Size: 1.05 KB

Versions: 1

Compression:

Stored size: 1.05 KB

Contents

require 'delayed_job'

module Delayed
  module Workless
    module Scaler
  
      class Base
        def self.jobs
          Delayed::Job.where(: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
          num_jobs = self.jobs.count
          @@scale_info ||= {
            0 => 0,
            100 => 1,
            500 => 2,
            1000 => 3
          }
          scale_key = @@scale_info.keys.reverse.select{|v| v <= num_jobs }.first
          if scale_key.nil?
            return 0
          else
            return @@scale_info[scale_key]
          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.13 lib/workless/scalers/base.rb