lib/dispatch-rider/demultiplexer.rb in dispatch-rider-0.2.6 vs lib/dispatch-rider/demultiplexer.rb in dispatch-rider-0.2.7
- old
+ new
@@ -33,11 +33,11 @@
private
def dispatch_message(message)
dispatcher.dispatch(message)
rescue => exception
- error_handler.call(message, exception)
+ handle_message_error message, exception
false
end
def do_loop
catch(:done) do
@@ -46,13 +46,40 @@
yield
end
end
end
+ def message_info_fragment(message)
+ "(#{message.object_id}): #{message.subject} : #{message.body.inspect}"
+ end
+
def handle_next_queue_item
queue.pop do |message|
- dispatch_message(message)
+ begin
+ logger.info "Starting execution of: #{message_info_fragment(message)}"
+ dispatch_message(message)
+ ensure
+ logger.info "Completed execution of: #{message_info_fragment(message)}"
+ end
end
+ end
+
+ def exception_info_fragment(message, exception)
+ "(#{message.object_id}): #{message.subject} with #{exception.class}: #{exception.message}"
+ end
+
+ def handle_message_error(message, exception)
+ begin
+ logger.error "Failed execution of: #{exception_info_fragment(message, exception)}"
+ error_handler.call(message, exception)
+ rescue => error_handler_exception # the error handler crashed
+ logger.error "Failed error handling of: #{exception_info_fragment(message, error_handler_exception)}"
+ raise error_handler_exception
+ end
+ end
+
+ def logger
+ DispatchRider.config.logger
end
end
end