Class: MessageQueue::ConsumableRunner

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/message_queue/consumable_runner.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

#logger, logger, logger=, setup_logger

Constructor Details

#initialize(consumables) ⇒ ConsumableRunner



7
8
9
# File 'lib/message_queue/consumable_runner.rb', line 7

def initialize(consumables)
  @consumables = consumables
end

Instance Attribute Details

#consumablesObject (readonly)

Returns the value of attribute consumables.



5
6
7
# File 'lib/message_queue/consumable_runner.rb', line 5

def consumables
  @consumables
end

Instance Method Details

#run(options = {}) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/message_queue/consumable_runner.rb', line 11

def run(options = {})
  begin
    block = !!options[:block]
    consumables.each_with_index do |consumable, index|
      # Blocks the last consumer
      opts = if index < consumables.size - 1
               {}
             else
               { :block => block }
             end
      consumable.new.subscribe(opts)
    end
  rescue SignalException => ex
    logger.info "Received Signal #{ex}"
  end
end