Class: Moonshot::Tools::ASGRollout

Inherits:
Object
  • Object
show all
Defined in:
lib/moonshot/tools/asg_rollout.rb,
lib/moonshot/tools/asg_rollout/asg.rb,
lib/moonshot/tools/asg_rollout/asg_instance.rb,
lib/moonshot/tools/asg_rollout/instance_health.rb,
lib/moonshot/tools/asg_rollout/hook_exec_environment.rb

Overview

rubocop:disable Metrics/ClassLength

Defined Under Namespace

Classes: ASG, ASGInstance, HookExecEnvironment, InstanceHealth

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(controller:, logical_id:) {|@config| ... } ⇒ ASGRollout

Returns a new instance of ASGRollout.

Yields:



8
9
10
11
12
13
# File 'lib/moonshot/tools/asg_rollout.rb', line 8

def initialize(controller:, logical_id:)
  @config = ASGRolloutConfig.new
  @controller = controller
  @logical_id = logical_id
  yield @config if block_given?
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



6
7
8
# File 'lib/moonshot/tools/asg_rollout.rb', line 6

def config
  @config
end

Instance Method Details

#run!Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/moonshot/tools/asg_rollout.rb', line 15

def run!
  increase_max_and_desired
  loop do
    new_instance = wait_for_new_instance
    begin
      wait_for_in_service(new_instance)
    rescue StandardError
      next
    end
    break
  end
  targets = asg.non_conforming_instances
  last_instance = targets.last

  targets.each do |instance|
    run_pre_detach(instance) if @config.pre_detach
    detach(instance, decrement: instance == last_instance)
    wait_for_out_of_service(instance)

    unless instance == last_instance
      new_instance = wait_for_new_instance
      wait_for_in_service(new_instance)
    end

    wait_for_terminate_when_hook(instance) if @config.terminate_when
    terminate(instance)
  end
ensure
  log.start_threaded 'Restoring MaxSize/DesiredCapacity values to normal...' do |s|
    asg.set_max_and_desired(@max, @desired)
    s.success 'Restored MaxSize/DesiredCapacity values to normal!'
  end
end