Sha256: bab0dd2178107a704dae56d5c10e255ec7e150c67dd9d2dc4c22e8745cf8be79

Contents?: true

Size: 660 Bytes

Versions: 4

Compression:

Stored size: 660 Bytes

Contents

require 'heroku'

module Delayed
  module Workless
    module Scaler

      class HerokuCedar < Base

        extend Delayed::Workless::Scaler::HerokuClient

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

        def self.down
          nw = self.calculate_num_workers
          client.ps_scale(ENV['APP_NAME'], :type => 'worker', :qty => nw) unless self.workers == 0 or self.jobs.count > 0
        end

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

      end

    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rcarvalho-workless-1.0.2.5 lib/workless/scalers/heroku_cedar.rb
rcarvalho-workless-1.0.2.4 lib/workless/scalers/heroku_cedar.rb
rcarvalho-workless-1.0.2.3 lib/workless/scalers/heroku_cedar.rb
rcarvalho-workless-1.0.2.2 lib/workless/scalers/heroku_cedar.rb