Class: DispatchRider::Demultiplexer

Inherits:
Object
  • Object
show all
Defined in:
lib/dispatch-rider/demultiplexer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(queue, dispatcher, error_handler) ⇒ Demultiplexer

Returns a new instance of Demultiplexer.



10
11
12
13
14
15
16
# File 'lib/dispatch-rider/demultiplexer.rb', line 10

def initialize(queue, dispatcher, error_handler)
  @queue = queue
  @dispatcher = dispatcher
  @error_handler = error_handler
  @continue = true
  @current_message = nil
end

Instance Attribute Details

#dispatcherObject (readonly)

Returns the value of attribute dispatcher.



8
9
10
# File 'lib/dispatch-rider/demultiplexer.rb', line 8

def dispatcher
  @dispatcher
end

#error_handlerObject (readonly)

Returns the value of attribute error_handler.



8
9
10
# File 'lib/dispatch-rider/demultiplexer.rb', line 8

def error_handler
  @error_handler
end

#queueObject (readonly)

Returns the value of attribute queue.



8
9
10
# File 'lib/dispatch-rider/demultiplexer.rb', line 8

def queue
  @queue
end

Instance Method Details

#startObject



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/dispatch-rider/demultiplexer.rb', line 18

def start
  do_loop do
    begin
      handle_next_queue_item
    rescue => exception
      error_handler.call(Message.new(subject: "TopLevelError", body: {}), exception)
      throw :done
    end
  end
  self
end

#stop(reason: nil) ⇒ Object



30
31
32
33
# File 'lib/dispatch-rider/demultiplexer.rb', line 30

def stop(reason: nil)
  @continue = false
  Logging::LifecycleLogger.log_got_stop reason, @current_message if @current_message
end