From 9701d67372d2e990b2cab95038b58f8f9882ea1d Mon Sep 17 00:00:00 2001 From: tlloydthwaites <91047784+tlloydthwaites@users.noreply.github.com> Date: Tue, 4 Jul 2023 11:42:14 +1000 Subject: [PATCH 1/3] Add delivery_info to properties for error handler When handling an error, it would be useful to know the delivery_info such as the routing key. This adds delivery_info to message properties. This seemed the only way to supply the information without changing the error handler contract. --- lib/hutch/worker.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/hutch/worker.rb b/lib/hutch/worker.rb index 1368839..4680509 100644 --- a/lib/hutch/worker.rb +++ b/lib/hutch/worker.rb @@ -74,6 +74,7 @@ def handle_message(consumer, delivery_info, properties, payload) @broker.ack(delivery_info.delivery_tag) unless consumer_instance.message_rejected? rescue => ex acknowledge_error(delivery_info, properties, @broker, ex) + properties = Bunny::MessageProperties.new(properties.to_hash.merge(delivery_info: delivery_info)) handle_error(properties, payload, consumer, ex) end From c66dc7139a467ef9398c86f1aca6f65ee83c59bc Mon Sep 17 00:00:00 2001 From: tlloydthwaites <91047784+tlloydthwaites@users.noreply.github.com> Date: Tue, 4 Jul 2023 16:11:43 +1000 Subject: [PATCH 2/3] Check error handler method arity Allows method handlers to specify delivery_info as the 5th parameter. Existing handlers will continue to only receive 4 parameters. --- lib/hutch/worker.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/hutch/worker.rb b/lib/hutch/worker.rb index 4680509..168c527 100644 --- a/lib/hutch/worker.rb +++ b/lib/hutch/worker.rb @@ -75,7 +75,7 @@ def handle_message(consumer, delivery_info, properties, payload) rescue => ex acknowledge_error(delivery_info, properties, @broker, ex) properties = Bunny::MessageProperties.new(properties.to_hash.merge(delivery_info: delivery_info)) - handle_error(properties, payload, consumer, ex) + handle_error(properties, payload, consumer, ex, delivery_info) end def with_tracing(klass) @@ -84,7 +84,7 @@ def with_tracing(klass) def handle_error(*args) Hutch::Config[:error_handlers].each do |backend| - backend.handle(*args) + backend.handle *args.first(backend.method(:handle).arity) end end From 4a906dd0fe271b1fd2b18758278330d1d9723cf5 Mon Sep 17 00:00:00 2001 From: tlloydthwaites <91047784+tlloydthwaites@users.noreply.github.com> Date: Wed, 5 Jul 2023 15:28:20 +1000 Subject: [PATCH 3/3] Update worker.rb --- lib/hutch/worker.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/hutch/worker.rb b/lib/hutch/worker.rb index 168c527..7ac1ae3 100644 --- a/lib/hutch/worker.rb +++ b/lib/hutch/worker.rb @@ -74,7 +74,6 @@ def handle_message(consumer, delivery_info, properties, payload) @broker.ack(delivery_info.delivery_tag) unless consumer_instance.message_rejected? rescue => ex acknowledge_error(delivery_info, properties, @broker, ex) - properties = Bunny::MessageProperties.new(properties.to_hash.merge(delivery_info: delivery_info)) handle_error(properties, payload, consumer, ex, delivery_info) end