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.



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

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.



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

def dispatcher
  @dispatcher
end

#error_handlerObject (readonly)

Returns the value of attribute error_handler.



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

def error_handler
  @error_handler
end

#queueObject (readonly)

Returns the value of attribute queue.



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

def queue
  @queue
end

Instance Method Details

#startObject



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

def start
  do_loop do

    sleep 1
    handle_next_queue_item
  rescue => exception
    error_handler.call(Message.new(subject: "TopLevelError", body: {}), exception)
    throw :done

  end
  self
end

#stop(reason: nil) ⇒ Object



33
34
35
36
# File 'lib/dispatch-rider/demultiplexer.rb', line 33

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