Sha256: 33f9aed607302e4cc840d63d13500ace9ace4c1bbcdfba8e8c444f95985d651d

Contents?: true

Size: 797 Bytes

Versions: 5

Compression:

Stored size: 797 Bytes

Contents

# frozen_string_literal: true

require "sneakers"

require "rabbit"
require "rabbit/receiving/receive"

class Rabbit::Receiving::Worker
  include Sneakers::Worker

  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

  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

  def handle_error!(error)
    raise if Rabbit.config.environment == :test
    Rabbit.config.exception_notifier.call(error)
    requeue!
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rabbit_messaging-0.12.1 lib/rabbit/receiving/worker.rb
rabbit_messaging-0.12.0 lib/rabbit/receiving/worker.rb
rabbit_messaging-0.11.0 lib/rabbit/receiving/worker.rb
rabbit_messaging-0.10.0 lib/rabbit/receiving/worker.rb
rabbit_messaging-0.9.0 lib/rabbit/receiving/worker.rb