lib/ears/consumer.rb in ears-0.3.0 vs lib/ears/consumer.rb in ears-0.3.1
- old
+ new
@@ -1,9 +1,9 @@
require 'bunny'
module Ears
- class Consumer < Bunny::Consumer
+ class Consumer
class InvalidReturnError < StandardError
def initialize(value)
super(
"#work must return :ack, :reject or :requeue, received #{value.inspect} instead",
)
@@ -47,29 +47,22 @@
private
def work_proc
->(delivery_info, metadata, payload) do
work(delivery_info, metadata, payload).tap do |result|
- process_result(result, delivery_info.delivery_tag)
+ verify_result(result)
end
end
end
def nest_middleware(middleware, next_middleware)
->(delivery_info, metadata, payload) do
middleware.call(delivery_info, metadata, payload, next_middleware)
end
end
- def process_result(result, delivery_tag)
- case result
- when :ack
- channel.ack(delivery_tag, false)
- when :reject
- channel.reject(delivery_tag)
- when :requeue
- channel.reject(delivery_tag, true)
- else
+ def verify_result(result)
+ unless %i[ack reject requeue].include?(result)
raise InvalidReturnError, result
end
end
end
end