Class: Autoscaler::Sidekiq::CelluloidMonitor
- Inherits:
-
Object
- Object
- Autoscaler::Sidekiq::CelluloidMonitor
- Includes:
- Celluloid
- Defined in:
- lib/autoscaler/sidekiq/celluloid_monitor.rb
Overview
Actor to monitor the sidekiq server for scale-down
Instance Method Summary collapse
-
#finished_job ⇒ Object
Notify the monitor that a job has finished.
-
#initialize(scaler, strategy, system) ⇒ CelluloidMonitor
constructor
A new instance of CelluloidMonitor.
-
#starting_job ⇒ Object
Notify the monitor that a job is starting.
-
#wait_for_downscale(interval = 15) ⇒ Object
Periodically update the desired number of workers.
Constructor Details
#initialize(scaler, strategy, system) ⇒ CelluloidMonitor
Returns a new instance of CelluloidMonitor.
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_job ⇒ Object
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_job ⇒ Object
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
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 |