Skip to content

Commit

Permalink
Five sec pause between stack event queries and eight retires should t…
Browse files Browse the repository at this point in the history
…ake care of rate limit errors. Fixes #2.
  • Loading branch information
Bittrance committed Jan 12, 2017
1 parent 5f793e3 commit 8ed3cd5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
11 changes: 6 additions & 5 deletions lib/cuffsert/rxcfclient.rb
Expand Up @@ -2,15 +2,15 @@
require 'cuffsert/cfstates'
require 'rx'

# TODO:
# - throttle describe_stack_events calls
# - retry on "5xx" errors

module CuffSert
class RxCFClient
def initialize(aws_cf = Aws::CloudFormation::Client.new, max_items: 1000)
def initialize(
aws_cf = Aws::CloudFormation::Client.new(retry_limit: 8),
pause: 5,
max_items: 1000)
@cf = aws_cf
@max_items = max_items
@pause = pause
end

def find_stack_blocking(meta)
Expand Down Expand Up @@ -86,6 +86,7 @@ def stack_events(stack_id, start_time)
end
state = @cf.describe_stacks(stack_name: stack_id)[:stacks][0]
break if stack_finished?(state)
sleep(@pause)
end
end
end
Expand Down
12 changes: 6 additions & 6 deletions spec/cuffsert/rxcfclient_spec.rb
Expand Up @@ -29,7 +29,7 @@
mock
end

subject { described_class.new(aws_mock).find_stack_blocking(meta) }
subject { described_class.new(aws_mock, pause: 0).find_stack_blocking(meta) }

it { should include(:stack_name => stack_name) }
end
Expand All @@ -48,7 +48,7 @@
mock
end

subject { described_class.new(aws_mock).find_stack_blocking(meta) }
subject { described_class.new(aws_mock, pause: 0).find_stack_blocking(meta) }

it { should be(nil) }
end
Expand Down Expand Up @@ -85,7 +85,7 @@
]
end

subject { described_class.new(aws_mock).create_stack(cfargs) }
subject { described_class.new(aws_mock, pause: 0).create_stack(cfargs) }

it { expect(subject).to emit_exactly(r1_done, r2_progress, r2_done) }
end
Expand All @@ -104,7 +104,7 @@
]
end

subject { described_class.new(aws_mock).create_stack(cfargs) }
subject { described_class.new(aws_mock, pause: 0).create_stack(cfargs) }

it { expect(subject).to emit_exactly(r1_done, r2_progress, r2_deleted) }
end
Expand All @@ -118,7 +118,7 @@
mock
end

subject { described_class.new(aws_mock).prepare_update(cfargs) }
subject { described_class.new(aws_mock, pause: 0).prepare_update(cfargs) }

it 'returns change_set when ready' do
expect(aws_mock).to receive(:describe_change_set)
Expand Down Expand Up @@ -163,7 +163,7 @@
mock
end

subject { described_class.new(aws_mock).update_stack(stack_id, change_set_id) }
subject { described_class.new(aws_mock, pause: 0).update_stack(stack_id, change_set_id) }

it { expect(subject).to emit_exactly(r1_done, r2_progress, r2_done) }
end
Expand Down

0 comments on commit 8ed3cd5

Please sign in to comment.