Skip to content

Commit

Permalink
Sum the x-death to handle failures with different reasons
Browse files Browse the repository at this point in the history
  • Loading branch information
jaronkk committed Apr 21, 2015
1 parent 11cdcbc commit 13ff822
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/sneakers/handlers/maxretry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 13ff822

Please sign in to comment.