Class: CfnCli::EventStreamer
- Inherits:
-
Object
- Object
- CfnCli::EventStreamer
- Defined in:
- lib/cfncli/event_streamer.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#stack ⇒ Object
readonly
Returns the value of attribute stack.
Instance Method Summary collapse
- #default_config ⇒ Object
-
#each_event(&block) ⇒ Object
Wait for events.
-
#initialize(stack, config = nil) ⇒ EventStreamer
constructor
A new instance of EventStreamer.
- #list_events(&block) ⇒ Object
-
#reset_events ⇒ Object
Mark all the existing events as ‘seen’.
Constructor Details
#initialize(stack, config = nil) ⇒ EventStreamer
Returns a new instance of EventStreamer.
10 11 12 13 14 |
# File 'lib/cfncli/event_streamer.rb', line 10 def initialize(stack, config = nil) @stack = stack @config = config || default_config @seen_events = [] end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
8 9 10 |
# File 'lib/cfncli/event_streamer.rb', line 8 def config @config end |
#stack ⇒ Object (readonly)
Returns the value of attribute stack.
7 8 9 |
# File 'lib/cfncli/event_streamer.rb', line 7 def stack @stack end |
Instance Method Details
#default_config ⇒ Object
16 17 18 |
# File 'lib/cfncli/event_streamer.rb', line 16 def default_config Config::CfnClient.new end |
#each_event(&block) ⇒ Object
Wait for events. This will exit when the stack reaches a finished state
23 24 25 26 27 28 |
# File 'lib/cfncli/event_streamer.rb', line 23 def each_event(&block) Waiting.wait(interval: config.interval, max_attempts: config.retries) do |waiter| list_events(&block) waiter.done if stack.finished? end end |
#list_events(&block) ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/cfncli/event_streamer.rb', line 30 def list_events(&block) events = [] @next_token = stack.events(@next_token).each { |event| events << event } events.sort { |a, b| a. <=> b. }.each do |event| yield event unless seen?(event) if block_given? end rescue Aws::CloudFormation::Errors::ServiceError => e raise unless e.class.name == 'Aws::CloudFormation::Errors::Throttling' end |
#reset_events ⇒ Object
Mark all the existing events as ‘seen’
41 42 43 |
# File 'lib/cfncli/event_streamer.rb', line 41 def reset_events list_events do; end end |