From 13ff82211b05d7eb07aa0cf50a60540e156701f4 Mon Sep 17 00:00:00 2001 From: Jaron Kennel Date: Tue, 21 Apr 2015 10:50:41 -0400 Subject: [PATCH] Sum the x-death to handle failures with different reasons --- lib/sneakers/handlers/maxretry.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/sneakers/handlers/maxretry.rb b/lib/sneakers/handlers/maxretry.rb index d0f00610..db8f1c41 100644 --- a/lib/sneakers/handlers/maxretry.rb +++ b/lib/sneakers/handlers/maxretry.rb @@ -168,10 +168,12 @@ def failure_count(headers) x_death_array = headers['x-death'].select do |x_death| x_death['queue'] == @worker_queue_name end - if x_death_array.count != 1 - x_death_array.count + if x_death_array.count > 0 && x_death_array.first['count'] + # Newer versions of RabbitMQ return headers with a count key + x_death_array.inject(0) {|sum, x_death| sum + x_death['count']} else - x_death_array.first['count'] || 1 + # Older versions return a separate x-death header for each failure + x_death_array.count end end end