Class: Stackup::StackWatcher
- Inherits:
-
Object
- Object
- Stackup::StackWatcher
- Defined in:
- lib/stackup/stack_watcher.rb
Overview
A stack event observer.
Keeps track of previously processed events, and yields the new ones.
Instance Attribute Summary collapse
-
#stack ⇒ Object
Returns the value of attribute stack.
Instance Method Summary collapse
-
#each_new_event ⇒ Object
Yield all events since the last call.
-
#initialize(stack) ⇒ StackWatcher
constructor
A new instance of StackWatcher.
-
#zero ⇒ Object
Consume all new events.
Constructor Details
#initialize(stack) ⇒ StackWatcher
Returns a new instance of StackWatcher.
11 12 13 |
# File 'lib/stackup/stack_watcher.rb', line 11 def initialize(stack) @stack = stack end |
Instance Attribute Details
#stack ⇒ Object
Returns the value of attribute stack.
15 16 17 |
# File 'lib/stackup/stack_watcher.rb', line 15 def stack @stack end |
Instance Method Details
#each_new_event ⇒ Object
Yield all events since the last call
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/stackup/stack_watcher.rb', line 19 def each_new_event # rubocop:disable Lint/HandleExceptions new_events = [] stack.events.each do |event| break if event.id == @last_processed_event_id new_events.unshift(event) end new_events.each do |event| yield event @last_processed_event_id = event.id end rescue Aws::CloudFormation::Errors::ValidationError end |
#zero ⇒ Object
Consume all new events
35 36 37 38 39 40 41 |
# File 'lib/stackup/stack_watcher.rb', line 35 def zero # rubocop:disable Lint/HandleExceptions last_event = stack.events.first @last_processed_event_id = last_event.id unless last_event.nil? nil rescue Aws::CloudFormation::Errors::ValidationError end |