Module: HerokuDjAutoScale::Scaler
- Defined in:
- lib/heroku_dj_auto_scale.rb
Class Method Summary collapse
- .heroku ⇒ Object
- .job_count ⇒ Object
- .job_count_unlocked ⇒ Object
- .stack ⇒ Object
- .workers ⇒ Object
- .workers=(qty) ⇒ Object
Class Method Details
.heroku ⇒ Object
8 9 10 |
# File 'lib/heroku_dj_auto_scale.rb', line 8 def heroku @heroku ||= Heroku::Client.new(ENV['HEROKU_USER'], ENV['HEROKU_PASS']) if ENV['USE_HEROKU_SCALING'] == 'true' end |
.job_count ⇒ Object
44 45 46 |
# File 'lib/heroku_dj_auto_scale.rb', line 44 def job_count Delayed::Job.all.count.to_i end |
.job_count_unlocked ⇒ Object
48 49 50 |
# File 'lib/heroku_dj_auto_scale.rb', line 48 def job_count_unlocked Delayed::Job.where(:locked_by => nil).count.to_i end |
.stack ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/heroku_dj_auto_scale.rb', line 12 def stack if ENV['USE_HEROKU_SCALING'] == 'true' heroku.list_stacks(ENV['HEROKU_APP']).inject("") do |current,stack| stack["current"] ? stack["name"] : current end else "current" end end |
.workers ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/heroku_dj_auto_scale.rb', line 22 def workers if ENV['USE_HEROKU_SCALING'] == 'true' if stack == "cedar" heroku.ps(ENV['HEROKU_APP']).count { |p| p["process"] =~ /worker\.\d?/ } else heroku.info(ENV['HEROKU_APP'])[:workers].to_i end else 1 end end |
.workers=(qty) ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/heroku_dj_auto_scale.rb', line 34 def workers=(qty) if ENV['USE_HEROKU_SCALING'] == 'true' if stack == "cedar" heroku.ps_scale(ENV['HEROKU_APP'], :type => 'worker', :qty => qty) else heroku.set_workers(ENV['HEROKU_APP'], qty) end end end |