Method: Jets::Commands::Deploy#find_stack

Defined in:
lib/jets/commands/deploy.rb

#find_stack(stack_name) ⇒ Object



128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/jets/commands/deploy.rb', line 128

def find_stack(stack_name)
  retries = 0
  resp = cfn.describe_stacks(stack_name: stack_name)
  resp.stacks.first
rescue Aws::CloudFormation::Errors::ValidationError => e
  # example: Stack with id demo-dev does not exist
  if e.message =~ /Stack with/ && e.message =~ /does not exist/
    nil
  else
    raise
  end
rescue Aws::CloudFormation::Errors::Throttling => e
  retries += 1
  seconds = 2 ** retries

  puts "WARN: find_stack #{e.class} #{e.message}".color(:yellow)
  puts "Backing off and will retry in #{seconds} seconds."
  sleep(seconds)
  if seconds > 90 # 2 ** 6 is 64 so will give up after 6 retries
    puts "Giving up after #{retries} retries"
  else
    retry
  end
end