Class: Autoscaler::Sidekiq::CelluloidMonitor

Inherits:
Object
  • Object
show all
Includes:
Celluloid
Defined in:
lib/autoscaler/sidekiq/celluloid_monitor.rb

Overview

Actor to monitor the sidekiq server for scale-down

Instance Method Summary collapse

Constructor Details

#initialize(scaler, strategy, system) ⇒ CelluloidMonitor

Returns a new instance of CelluloidMonitor.

Parameters:

  • scaler (scaler)

    object that actually performs scaling operations (e.g. HerokuScaler)

  • strategy (Strategy)

    object that decides the target number of workers (e.g. BinaryScalingStrategy)

  • system (System)

    interface to the queuing system for use by the strategy



13
14
15
16
17
18
# File 'lib/autoscaler/sidekiq/celluloid_monitor.rb', line 13

def initialize(scaler, strategy, system)
  @scaler = scaler
  @strategy = strategy
  @system = system
  @running = false
end

Instance Method Details

#finished_jobObject

Notify the monitor that a job has finished



41
42
43
44
# File 'lib/autoscaler/sidekiq/celluloid_monitor.rb', line 41

def finished_job
  active_now!
  async.wait_for_downscale
end

#starting_jobObject

Notify the monitor that a job is starting



37
38
# File 'lib/autoscaler/sidekiq/celluloid_monitor.rb', line 37

def starting_job
end

#wait_for_downscale(interval = 15) ⇒ Object

Periodically update the desired number of workers

Parameters:

  • interval (Numeric) (defaults to: 15)

    polling interval, mostly for testing



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/autoscaler/sidekiq/celluloid_monitor.rb', line 22

def wait_for_downscale(interval = 15)
  once do
    active_now!

    workers = :unknown

    begin
      sleep(interval)
      target_workers = @strategy.call(@system, idle_time)
      workers = @scaler.workers = target_workers unless workers == target_workers
    end while workers > 0
  end
end