Class: Autoscaler::DelayedShutdown

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

Overview

This is a sort of middleware that keeps the last worker up for a minimum amount of time

Instance Method Summary collapse

Constructor Details

#initialize(strategy, timeout) ⇒ DelayedShutdown



6
7
8
9
10
# File 'lib/autoscaler/delayed_shutdown.rb', line 6

def initialize(strategy, timeout)
  @strategy = strategy
  @timeout = timeout
  active_now!
end

Instance Method Details

#call(system, event_idle_time) ⇒ Integer



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/autoscaler/delayed_shutdown.rb', line 15

def call(system, event_idle_time)
  target_workers = strategy.call(system, event_idle_time)
  if target_workers > 0
    active_now!
    target_workers
  elsif time_left?(event_idle_time)
    1
  else
    0
  end
end