Class: Stackup::StackWatcher

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(stack) ⇒ StackWatcher

Returns a new instance of StackWatcher.



13
14
15
# File 'lib/stackup/stack_watcher.rb', line 13

def initialize(stack)
  @stack = stack
end

Instance Attribute Details

#stackObject

Returns the value of attribute stack.



17
18
19
# File 'lib/stackup/stack_watcher.rb', line 17

def stack
  @stack
end

Instance Method Details

#each_new_eventObject

Yield all events since the last call

rubocop:disable Lint/SuppressedException



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/stackup/stack_watcher.rb', line 22

def each_new_event
  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 => _e
end

#zeroObject

Consume all new events



38
39
40
41
42
43
# File 'lib/stackup/stack_watcher.rb', line 38

def zero
  last_event = stack.events.first
  @last_processed_event_id = last_event.id unless last_event.nil?
  nil
rescue Aws::CloudFormation::Errors::ValidationError
end