Class: Autoscaler::Sidekiq::MonitorMiddlewareAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/autoscaler/sidekiq/monitor_middleware_adapter.rb

Overview

Shim to the existing autoscaler interface Starts the monitor and notifies it of job events that may occur while it’s sleeping

Instance Method Summary collapse

Constructor Details

#initialize(scaler, timeout, specified_queues = nil) ⇒ MonitorMiddlewareAdapter

Returns a new instance of MonitorMiddlewareAdapter.

Parameters:

  • scaler (scaler)

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

  • timeout (Strategy, Numeric)

    strategy object that determines target workers, or a timeout in seconds to be passed to DelayedShutdown+BinaryScalingStrategy

  • specified_queues (Array[String]) (defaults to: nil)

    list of queues to monitor to determine if there is work left. Defaults to all sidekiq queues.



14
15
16
17
18
19
20
21
# File 'lib/autoscaler/sidekiq/monitor_middleware_adapter.rb', line 14

def initialize(scaler, timeout, specified_queues = nil)
  unless monitor
    CelluloidMonitor.supervise_as(:autoscaler_monitor,
                                  scaler,
                                  strategy(timeout),
                                  QueueSystem.new(specified_queues))
  end
end

Instance Method Details

#call(worker, msg, queue, _ = nil) ⇒ Object

Sidekiq middleware api entry point



24
25
26
27
28
29
30
# File 'lib/autoscaler/sidekiq/monitor_middleware_adapter.rb', line 24

def call(worker, msg, queue, _ = nil)
  monitor.async.starting_job
  yield
ensure
  # monitor might have gone, e.g. if Sidekiq has received SIGTERM
  monitor.async.finished_job if monitor
end