lib/jets/commands/clean/log.rb in jets-2.1.1 vs lib/jets/commands/clean/log.rb in jets-2.1.2
- old
+ new
@@ -17,13 +17,30 @@
are_you_sure?("delete CloudWatch logs")
say "Removing CloudWatch logs for #{prefix_guess}..."
log_groups.each do |g|
next if keep_log_group?(g.log_group_name)
- logs.delete_log_group(log_group_name: g.log_group_name) unless @options[:noop]
+ delete_log_group(g.log_group_name) unless @options[:noop]
say "Removed log group: #{g.log_group_name}"
end
say "Removed CloudWatch logs for #{prefix_guess}"
+ end
+
+ def delete_log_group(log_group_name)
+ retries = 0
+ logs.delete_log_group(log_group_name: log_group_name)
+ rescue Aws::CloudWatchLogs::Errors::ThrottlingException => e
+ retries += 1
+ seconds = 2 ** retries
+
+ puts "WARN: delete_log_group #{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
def clean_deploys
groups = deploy_log_groups.sort_by do |g|
g.log_group_name