Class: StackMaster::StackEvents::Streamer
- Inherits:
-
Object
- Object
- StackMaster::StackEvents::Streamer
- Defined in:
- lib/stack_master/stack_events/streamer.rb
Constant Summary collapse
- StackFailed =
Class.new(StandardError)
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(stack_name, region, from: Time.now, break_on_finish_state: true, sleep_between_fetches: 1, io: nil, &block) ⇒ Streamer
constructor
A new instance of Streamer.
- #stream ⇒ Object
Constructor Details
#initialize(stack_name, region, from: Time.now, break_on_finish_state: true, sleep_between_fetches: 1, io: nil, &block) ⇒ Streamer
Returns a new instance of Streamer.
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/stack_master/stack_events/streamer.rb', line 10 def initialize(stack_name, region, from: Time.now, break_on_finish_state: true, sleep_between_fetches: 1, io: nil, &block) @stack_name = stack_name @region = region @block = block @seen_events = Set.new @from = from @break_on_finish_state = break_on_finish_state @sleep_between_fetches = sleep_between_fetches @io = io end |
Class Method Details
.stream(stack_name, region, **args, &block) ⇒ Object
6 7 8 |
# File 'lib/stack_master/stack_events/streamer.rb', line 6 def self.stream(stack_name, region, **args, &block) new(stack_name, region, **args, &block).stream end |
Instance Method Details
#stream ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/stack_master/stack_events/streamer.rb', line 21 def stream catch(:halt) do loop do events = Fetcher.fetch(@stack_name, @region, from: @from) unseen_events(events).each do |event| @block.call(event) if @block Presenter.print_event(@io, event) if @io if @break_on_finish_state && finish_state?(event) exit_with_error(event) if failure_state?(event) throw :halt end end sleep @sleep_between_fetches end end rescue Interrupt end |