Class: Delayed::Workless::Scaler::Heroku
- Extended by:
- HerokuClient
- Defined in:
- lib/workless/scalers/heroku.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
17 18 19 20 21 |
# File 'lib/workless/scalers/heroku.rb', line 17 def self.down return if workers == workers_needed updates = { "quantity": workers_needed } client.formation.update(ENV['APP_NAME'], 'worker', updates) end |
.max_workers ⇒ Object
45 46 47 |
# File 'lib/workless/scalers/heroku.rb', line 45 def self.max_workers ENV['WORKLESS_MAX_WORKERS'].present? ? ENV['WORKLESS_MAX_WORKERS'].to_i : 1 end |
.min_workers ⇒ Object
49 50 51 |
# File 'lib/workless/scalers/heroku.rb', line 49 def self.min_workers ENV['WORKLESS_MIN_WORKERS'].present? ? ENV['WORKLESS_MIN_WORKERS'].to_i : 0 end |
.up ⇒ Object
11 12 13 14 15 |
# File 'lib/workless/scalers/heroku.rb', line 11 def self.up return unless workers_needed > min_workers && workers < workers_needed updates = { "quantity": workers_needed } client.formation.update(ENV['APP_NAME'], 'worker', updates) end |
.workers ⇒ Object
23 24 25 |
# File 'lib/workless/scalers/heroku.rb', line 23 def self.workers client.formation.info(ENV['APP_NAME'], 'worker')['quantity'].to_i end |
.workers_needed ⇒ Object
33 34 35 |
# File 'lib/workless/scalers/heroku.rb', line 33 def self.workers_needed [[(jobs.count.to_f / workers_ratio).ceil, max_workers].min, min_workers].max end |
.workers_ratio ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/workless/scalers/heroku.rb', line 37 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 |