Sha256: da79b7683822a2e495050f1177fa4d9ec7e5a0a56ccf44f31592a77618c7ea39

Contents?: true

Size: 1.04 KB

Versions: 1

Compression:

Stored size: 1.04 KB

Contents

require 'heroku'

module Delayed
  module Workless
    module Scaler

      class HerokuCedar < Base

        extend Delayed::Workless::Scaler::HerokuClient

        def self.up
          @@current_num_workers || 0
          nw = self.calculate_num_workers
          if nw
            if @@current_num_workers != nw
              @@current_num_workers = nw
              client.ps_scale(ENV['APP_NAME'], :type => 'worker', :qty => @@current_num_workers) 
            end
          end
        rescue
        end

        def self.down
          @@current_num_workers || 0
          nw = self.calculate_num_workers
          if nw
            if @@current_num_workers != nw
              @@current_num_workers = nw
              client.ps_scale(ENV['APP_NAME'], :type => 'worker', :qty => nw)
            end
          end          
        rescue
        end

        def self.workers
          @@current_num_workers || 0
          @@current_num_workers || client.ps(ENV['APP_NAME']).count { |p| p["process"] =~ /worker\.\d?/ }
        end

      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rcarvalho-workless-1.0.2.8 lib/workless/scalers/heroku_cedar.rb