Class: AwsAsCode::StackStateSemaphore

Inherits:
Object
  • Object
show all
Includes:
Term::ANSIColor
Defined in:
lib/aws_as_code/stack_state_semaphore.rb

Instance Method Summary collapse

Constructor Details

#initialize(logger:) ⇒ StackStateSemaphore

Returns a new instance of StackStateSemaphore.



7
8
9
# File 'lib/aws_as_code/stack_state_semaphore.rb', line 7

def initialize(logger:)
  @logger = logger
end

Instance Method Details

#wait(stack) ⇒ Object



11
12
13
14
15
# File 'lib/aws_as_code/stack_state_semaphore.rb', line 11

def wait(stack)
  wait_for_stack_availability stack
  yield
  wait_for_stack_availability stack
end

#wait_for_stack_availability(stack) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/aws_as_code/stack_state_semaphore.rb', line 17

def wait_for_stack_availability(stack)
  # Note that stack can have old state cached, hence explicit
  # .reload here
  stack.reload.wait_until(max_attempts: 360, delay: 10) do |s|
    if in_progress? s
      log_waiting s
      false
    else
      log_proceeding s
      true
    end
  end
end