Skip to content

Commit

Permalink
add exponential back off retry
Browse files Browse the repository at this point in the history
  • Loading branch information
maratoid committed Jun 18, 2014
1 parent 8211444 commit cccf4d8
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 12 deletions.
2 changes: 1 addition & 1 deletion zerg/lib/zerg/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@
#++

module Zerg
VERSION = "0.0.16"
VERSION = "0.0.17"
end
2 changes: 1 addition & 1 deletion zerg/zerg.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Gem::Specification.new do |s|
s.add_dependency "thor"
s.add_dependency "highline"
s.add_dependency "zergrush_vagrant", ">= 0.0.4"
s.add_dependency "zergrush_cf", ">= 0.0.9"
s.add_dependency "zergrush_cf", ">= 0.0.10"

s.files = `git ls-files`.split("\n")
s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
Expand Down
39 changes: 31 additions & 8 deletions zerg_plugins/zergrush_cf/lib/zergrush_cf/init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
require 'securerandom'
require 'bunny'
require 'time'
require 'retries'
require_relative 'renderer'

class CloudFormation < ZergGemPlugin::Plugin "/driver"
Expand Down Expand Up @@ -85,6 +86,10 @@ def rush hive_location, task_name, task_hash, debug
end
end

Excon.defaults[:connect_timeout] = 600
Excon.defaults[:read_timeout] = 600
Excon.defaults[:write_timeout] = 600

cf = Fog::AWS::CloudFormation.new(
:aws_access_key_id => aws_key_id,
:aws_secret_access_key => aws_secret,
Expand Down Expand Up @@ -112,10 +117,15 @@ def rush hive_location, task_name, task_hash, debug
outputs_info = cf.describe_stacks({ 'StackName' => stack_name })
end

events = cf.describe_stack_events(stack_name).body['StackEvents']
while events == nil do
sleep 1
events = nil
with_retries(:max_tries => 10, :base_sleep_seconds => 3, :max_sleep_seconds => 20, :rescue => Fog::AWS::CloudFormation::Error) {
events = cf.describe_stack_events(stack_name).body['StackEvents']
}
while events == nil do
sleep 3
with_retries(:max_tries => 10, :base_sleep_seconds => 3, :max_sleep_seconds => 20, :rescue => Fog::AWS::CloudFormation::Error) {
events = cf.describe_stack_events(stack_name).body['StackEvents']
}
end

event_counter = 0
Expand All @@ -124,7 +134,9 @@ def rush hive_location, task_name, task_hash, debug
logRabbitEvents(events.first(events.length - event_counter), rabbit_objects, eval_params(task_hash["vm"]["driver"]["driveroptions"][0]["rabbit"]))
event_counter = events.length

events = cf.describe_stack_events(stack_name).body['StackEvents']
with_retries(:max_tries => 10, :base_sleep_seconds => 3, :max_sleep_seconds => 20, :rescue => Fog::AWS::CloudFormation::Error) {
events = cf.describe_stack_events(stack_name).body['StackEvents']
}
outputs_info = cf.describe_stacks({ 'StackName' => stack_name })
if outputs_info.body["Stacks"][0]["StackStatus"] == "CREATE_COMPLETE"
logEvents(events.first(events.length - event_counter))
Expand Down Expand Up @@ -172,6 +184,10 @@ def clean hive_location, task_name, task_hash, debug
# run fog cleanup on the stack.
stack_name = "#{task_name}"

Excon.defaults[:connect_timeout] = 600
Excon.defaults[:read_timeout] = 600
Excon.defaults[:write_timeout] = 600

cf = Fog::AWS::CloudFormation.new(
:aws_access_key_id => aws_key_id,
:aws_secret_access_key => aws_secret,
Expand All @@ -196,11 +212,16 @@ def clean hive_location, task_name, task_hash, debug
end
end

events = cf.describe_stack_events(stack_name).body['StackEvents']
events = nil
with_retries(:max_tries => 10, :base_sleep_seconds => 3, :max_sleep_seconds => 20, :rescue => Fog::AWS::CloudFormation::Error) {
events = cf.describe_stack_events(stack_name).body['StackEvents']
}
while events == nil do
sleep 1
sleep 3
begin
events = cf.describe_stack_events(stack_name).body['StackEvents']
with_retries(:max_tries => 10, :base_sleep_seconds => 3, :max_sleep_seconds => 20, :rescue => Fog::AWS::CloudFormation::Error) {
events = cf.describe_stack_events(stack_name).body['StackEvents']
}
rescue Fog::AWS::CloudFormation::NotFound
rabbit_objects[:connection].close unless rabbit_objects == nil
return 0
Expand All @@ -214,7 +235,9 @@ def clean hive_location, task_name, task_hash, debug

event_counter = events.length
begin
events = cf.describe_stack_events(stack_name).body['StackEvents']
with_retries(:max_tries => 10, :base_sleep_seconds => 3, :max_sleep_seconds => 20, :rescue => Fog::AWS::CloudFormation::Error) {
events = cf.describe_stack_events(stack_name).body['StackEvents']
}
outputs_info = cf.describe_stacks({ 'StackName' => stack_name })
rescue Fog::AWS::CloudFormation::NotFound
logEvents(events.first(events.length - event_counter))
Expand Down
2 changes: 1 addition & 1 deletion zerg_plugins/zergrush_cf/lib/zergrush_cf/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@
#++

module ZergrushCF
VERSION = "0.0.9"
VERSION = "0.0.10"
end
3 changes: 2 additions & 1 deletion zerg_plugins/zergrush_cf/zergrush_cf.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ Gem::Specification.new do |s|

s.add_development_dependency "bundler", ">= 1.0.0"
s.add_development_dependency "rake"
s.add_development_dependency "zergrush", ">= 0.0.16"
s.add_development_dependency "zergrush", ">= 0.0.17"

s.add_dependency "fog", ">=1.20.0"
s.add_dependency "bunny", ">=1.2.1"
s.add_dependency "retries", ">=0.0.5"

s.files = `git ls-files`.split("\n")
s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
Expand Down

0 comments on commit cccf4d8

Please sign in to comment.