Class: SidekiqHerokuScaler::Strategy::Latency

Inherits:
Object
  • Object
show all
Defined in:
lib/sidekiq-heroku-scaler/strategy/latency.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(min_dynos_count:, max_dynos_count:, max_latency:, min_latency:, inc_count: nil, dec_count: nil, smart_decrease: false) ⇒ Latency

rubocop:disable Metrics/ParameterLists



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/sidekiq-heroku-scaler/strategy/latency.rb', line 9

def initialize(min_dynos_count:, max_dynos_count:,
               max_latency:, min_latency:,
               inc_count: nil, dec_count: nil,
               smart_decrease: false)
  @min_dynos_count = min_dynos_count
  @max_dynos_count = max_dynos_count
  @max_latency = max_latency
  @min_latency = min_latency
  @inc_count = (inc_count || 1).to_i
  @dec_count = (dec_count || 1).to_i
  @smart_decrease = smart_decrease
end

Instance Attribute Details

#dec_countObject (readonly)

Returns the value of attribute dec_count.



6
7
8
# File 'lib/sidekiq-heroku-scaler/strategy/latency.rb', line 6

def dec_count
  @dec_count
end

#inc_countObject (readonly)

Returns the value of attribute inc_count.



6
7
8
# File 'lib/sidekiq-heroku-scaler/strategy/latency.rb', line 6

def inc_count
  @inc_count
end

#smart_decreaseObject (readonly)

Returns the value of attribute smart_decrease.



6
7
8
# File 'lib/sidekiq-heroku-scaler/strategy/latency.rb', line 6

def smart_decrease
  @smart_decrease
end

Instance Method Details

#decrease?(sidekiq_worker) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
32
33
34
# File 'lib/sidekiq-heroku-scaler/strategy/latency.rb', line 29

def decrease?(sidekiq_worker)
  sidekiq_worker.quantity > min_dynos_count &&
    sidekiq_worker.latency < min_latency &&
    (sidekiq_worker.quantity > 1 || !sidekiq_worker.jobs_running?) &&
    (!sidekiq_worker.jobs_running? || safe_quantity(sidekiq_worker.quantity - dec_count).positive?)
end

#increase?(sidekiq_worker) ⇒ Boolean

rubocop:enable Metrics/ParameterLists

Returns:

  • (Boolean)


23
24
25
26
27
# File 'lib/sidekiq-heroku-scaler/strategy/latency.rb', line 23

def increase?(sidekiq_worker)
  sidekiq_worker.quantity < max_dynos_count &&
    (sidekiq_worker.latency > max_latency ||
      (sidekiq_worker.quantity.zero? && sidekiq_worker.latency.positive?))
end

#safe_quantity(quantity) ⇒ Object



36
37
38
39
40
# File 'lib/sidekiq-heroku-scaler/strategy/latency.rb', line 36

def safe_quantity(quantity)
  return min_dynos_count if quantity < min_dynos_count

  [quantity, max_dynos_count].min
end