Module: HerokuResqueAutoScale::Scaler

Defined in:
lib/heroku-resque-workers-scaler/scaler.rb

Constant Summary collapse

@@heroku =
PlatformAPI.connect(ENV['HEROKU_API_KEY'])

Class Method Summary collapse

Class Method Details

.job_countObject



36
37
38
# File 'lib/heroku-resque-workers-scaler/scaler.rb', line 36

def job_count
  Resque.info[:pending].to_i
end

.shut_down_workers!Object



31
32
33
34
# File 'lib/heroku-resque-workers-scaler/scaler.rb', line 31

def shut_down_workers!
  @@heroku.formation.update(app_name, worker_name, { quantity: 0 })
  nil
end

.workersObject



10
11
12
13
14
# File 'lib/heroku-resque-workers-scaler/scaler.rb', line 10

def workers
  return -1 unless authorized?
  result = @@heroku.formation.info(app_name, worker_name)
  result['quantity']
end

.workers=(quantity) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/heroku-resque-workers-scaler/scaler.rb', line 16

def workers=(quantity)
  return unless authorized?

  quantity = quantity.to_i

  if safe_mode?
    if scale_down? quantity
      return false unless all_jobs_have_been_processed?
    end
  end

  result = @@heroku.formation.update(app_name, worker_name, { quantity: quantity })
  result['quantity'] == quantity
end

.working_job_countObject



40
41
42
# File 'lib/heroku-resque-workers-scaler/scaler.rb', line 40

def working_job_count
  Resque.info[:working].to_i
end