lib/dispatch-rider/demultiplexer.rb in dispatch-rider-2.1.0 vs lib/dispatch-rider/demultiplexer.rb in dispatch-rider-2.2.0

- old
+ new

@@ -1,5 +1,7 @@ +# frozen_string_literal: true + # The demultiplexer in the reactor pattern is implemented in this class. # The object needs to be initiated with a queue and a dispatcher. # Demultiplexer#start defines an event loop which pops items from the queue # and passes it on to the dispatcher for dispatching to the appropriate message handler. # The demultiplexer can be stopped by calling the Demultiplexer#stop method. @@ -15,17 +17,17 @@ @current_message = nil end def start do_loop do - begin - sleep 1 - handle_next_queue_item - rescue => exception - error_handler.call(Message.new(subject: "TopLevelError", body: {}), exception) - throw :done - end + + sleep 1 + handle_next_queue_item + rescue => exception + error_handler.call(Message.new(subject: "TopLevelError", body: {}), exception) + throw :done + end self end def stop(reason: nil) @@ -34,16 +36,14 @@ end private def with_current_message(message) - begin - @current_message = message - yield - ensure - @current_message = nil - end + @current_message = message + yield + ensure + @current_message = nil end # This needs to return true/false based on the success of the jobs! def dispatch_message(message) with_current_message(message) do @@ -72,15 +72,13 @@ dispatch_message(message) end end def handle_message_error(message, exception) - begin - error_handler.call(message, exception) - rescue => error_handler_exception # the error handler crashed - Logging::LifecycleLogger.log_error_handler_fail message, error_handler_exception - raise error_handler_exception - end + error_handler.call(message, exception) + rescue => error_handler_exception # the error handler crashed + Logging::LifecycleLogger.log_error_handler_fail message, error_handler_exception + raise error_handler_exception end def logger DispatchRider.config.logger end