Class: Rabbit::Receiving::Worker

Inherits:
Object
  • Object
show all
Includes:
Sneakers::Worker
Defined in:
lib/rabbit/receiving/worker.rb

Instance Method Summary collapse

Instance Method Details

#handle_error!(error) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/rabbit/receiving/worker.rb', line 27

def handle_error!(error)
  raise if Rabbit.config.environment == :test
  Rabbit.config.exception_notifier.call(error)
  # wait to prevent queue overflow
  sleep 1
  requeue!
end

#receive_message(message, delivery_info, arguments) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/rabbit/receiving/worker.rb', line 19

def receive_message(message, delivery_info, arguments)
  Rabbit::Receiving::Receive.new(
    message: message.dup.force_encoding("UTF-8"),
    delivery_info: delivery_info,
    arguments: arguments,
  ).call
end

#work_with_params(message, delivery_info, arguments) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/rabbit/receiving/worker.rb', line 11

def work_with_params(message, delivery_info, arguments)
  # args and info have custom rabbit classes, have to convert them to hash
  receive_message(message, delivery_info.to_h, arguments.to_h)
  ack!
rescue => error
  handle_error!(error)
end