Class: Delayed::Workless::Scaler::HerokuCedar
- Extended by:
- HerokuClient
- Defined in:
- lib/workless/scalers/heroku_cedar.rb
Class Method Summary collapse
- .down ⇒ Object
- .max_workers ⇒ Object
- .min_workers ⇒ Object
- .up ⇒ Object
- .workers ⇒ Object
-
.workers_needed ⇒ Object
Returns the number of workers needed based on the current number of pending jobs and the settings defined by:.
- .workers_ratio ⇒ Object
Methods included from HerokuClient
Methods inherited from Base
Class Method Details
.down ⇒ Object
13 14 15 |
# File 'lib/workless/scalers/heroku_cedar.rb', line 13 def self.down client.post_ps_scale(ENV['APP_NAME'], 'worker', self.min_workers) unless self.jobs.count > 0 or self.workers == self.min_workers end |
.max_workers ⇒ Object
39 40 41 |
# File 'lib/workless/scalers/heroku_cedar.rb', line 39 def self.max_workers ENV['WORKLESS_MAX_WORKERS'].present? ? ENV['WORKLESS_MAX_WORKERS'].to_i : 1 end |
.min_workers ⇒ Object
43 44 45 |
# File 'lib/workless/scalers/heroku_cedar.rb', line 43 def self.min_workers ENV['WORKLESS_MIN_WORKERS'].present? ? ENV['WORKLESS_MIN_WORKERS'].to_i : 0 end |
.up ⇒ Object
9 10 11 |
# File 'lib/workless/scalers/heroku_cedar.rb', line 9 def self.up client.post_ps_scale(ENV['APP_NAME'], 'worker', self.workers_needed) if self.workers_needed > self.min_workers and self.workers < self.workers_needed end |
.workers ⇒ Object
17 18 19 |
# File 'lib/workless/scalers/heroku_cedar.rb', line 17 def self.workers client.get_ps(ENV['APP_NAME']).body.count { |p| p["process"] =~ /worker\.\d?/ } end |
.workers_needed ⇒ Object
27 28 29 |
# File 'lib/workless/scalers/heroku_cedar.rb', line 27 def self.workers_needed [[(self.jobs.count.to_f / self.workers_ratio).ceil, self.max_workers].min, self.min_workers].max end |
.workers_ratio ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/workless/scalers/heroku_cedar.rb', line 31 def self.workers_ratio if ENV['WORKLESS_WORKERS_RATIO'].present? && (ENV['WORKLESS_WORKERS_RATIO'].to_i != 0) ENV['WORKLESS_WORKERS_RATIO'].to_i else 100 end end |