class Dpl::Providers::Cloudformation::EventStream
Constants
- EVENT_KEYS
Attributes
thread[R]
Public Class Methods
new(*)
click to toggle source
Calls superclass method
# File lib/dpl/providers/cloudformation.rb, line 219 def initialize(*) super @event = describe_stack_events.stack_events.first @thread = Thread.new(&method(:process)) end
Public Instance Methods
stop()
click to toggle source
# File lib/dpl/providers/cloudformation.rb, line 225 def stop mutex.synchronize { @stop = true } thread.join end
Private Instance Methods
describe_stack_events()
click to toggle source
# File lib/dpl/providers/cloudformation.rb, line 259 def describe_stack_events client.describe_stack_events(stack_name:) end
events_since(event)
click to toggle source
source: github.com/rvedotrc/cfn-events/blob/master/lib/cfn-events/runner.rb
# File lib/dpl/providers/cloudformation.rb, line 241 def events_since(event) described_stack = describe_stack_events stack_events = described_stack.stack_events return [event, []] if stack_events.first.event_id == event.event_id events = [] described_stack.each_page do |page| if (oldest_new = page.stack_events.index { |e| e.event_id == event.event_id }) events.concat(page.stack_events[0..oldest_new - 1]) return [events.first, events.reverse] end events.concat(page.stack_events) end warn %(Last-seen stack event is no longer returned by AWS. Please raise this as a provider's bug.) [events.first, events.reverse] end
format_event(event)
click to toggle source
# File lib/dpl/providers/cloudformation.rb, line 270 def format_event(event) parts = EVENT_KEYS.map { |key| event.send(key) } parts[0] = format_timestamp(parts[0]) parts.join(' ') end
format_timestamp(timestamp)
click to toggle source
# File lib/dpl/providers/cloudformation.rb, line 276 def format_timestamp(timestamp) timestamp.utc.strftime('%Y-%m-%dT%H:%M:%SZ') end
mutex()
click to toggle source
# File lib/dpl/providers/cloudformation.rb, line 263 def mutex @mutex ||= Mutex.new end
process()
click to toggle source
# File lib/dpl/providers/cloudformation.rb, line 232 def process until mutex.synchronize { @stop } @event, events = events_since(@event) events.each { |e| handler.call(format_event(e)) } sleep 5 unless ENV['ENV'] == 'test' end end