lib/sneakers/handlers/maxretry.rb in sneakers-1.0.3 vs lib/sneakers/handlers/maxretry.rb in sneakers-1.0.4
- old
+ new
@@ -163,12 +163,19 @@
# @return [Integer] Count of number of failures.
def failure_count(headers)
if headers.nil? || headers['x-death'].nil?
0
else
- headers['x-death'].select do |x_death|
+ x_death_array = headers['x-death'].select do |x_death|
x_death['queue'] == @worker_queue_name
- end.count
+ end
+ 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
+ # Older versions return a separate x-death header for each failure
+ x_death_array.count
+ end
end
end
private :failure_count
# Prefix all of our log messages so they are easier to find. We don't have