Module: Stackit::Wait

Included in:
ManagedStack, Mixin::OpsWorks
Defined in:
lib/stackit/wait.rb

Instance Method Summary collapse

Instance Method Details

#wait_for_stack(status_pattern = /COMPLETE/) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/stackit/wait.rb', line 19

def wait_for_stack(status_pattern = /COMPLETE/)
  Stackit.logger.debug "Waiting for stack #{stack_name} to complete..."
  wait_for(timeout: 15.minutes) do
    stack = Stack.new(stack_name: stack_name).hydrate!
    case stack.stack_status
    when /FAILED/
      raise WaitError, "Stack failed during wait: #{stack_name}"
    when status_pattern
      yield stack if block_given?
      true
    else
      false
    end
  end
end

#wait_for_stack_to_deleteObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/stackit/wait.rb', line 35

def wait_for_stack_to_delete
  Stackit.logger.debug "Waiting for stack #{stack_name} to delete..."
  wait_for(timeout: 15.minutes) do
    begin
      stack = Stack.new(stack_name: stack_name).hydrate!
      if stack.nil?
        yield stack if block_given?
        true
      else
        false
      end
    rescue Aws::CloudFormation::Errors::ValidationError => e
      if e.message.include?("does not exist")
        true
      end
    end
  end
end

#wait_until_stack_has_key(key) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/stackit/wait.rb', line 7

def wait_until_stack_has_key(key)
  Stackit.logger.debug "Waiting until stack #{stack_name} has key #{key}..."
  wait_for(timeout: 15.minutes) do
    stack = Stack.new(stack_name: stack_name).hydrate!
    raise "Stack failure: #{stack.stack_status}" if stack.stack_status =~ /FAILED/
    if stack[key]
      yield stack if block_given?
      true
    end
  end
end