Class: Totoro::EnqueueService
- Inherits:
-
Object
- Object
- Totoro::EnqueueService
- Defined in:
- lib/totoro/services/enqueue_service.rb
Instance Method Summary collapse
- #enqueue(id, payload, attrs = {}) ⇒ Object
-
#initialize(connection, config) ⇒ EnqueueService
constructor
A new instance of EnqueueService.
Constructor Details
#initialize(connection, config) ⇒ EnqueueService
Returns a new instance of EnqueueService.
5 6 7 8 |
# File 'lib/totoro/services/enqueue_service.rb', line 5 def initialize(connection, config) @connection = connection @config = config end |
Instance Method Details
#enqueue(id, payload, attrs = {}) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/totoro/services/enqueue_service.rb', line 10 def enqueue(id, payload, attrs = {}) @connection.start unless @connection.connected? queue = channel.queue(*@config.queue(id)) payload = JSON.dump payload exchange.publish(payload, (id, queue.name, attrs)) Rails.logger.debug "send message to #{queue.name}" STDOUT.flush channel.close rescue Bunny::TCPConnectionFailedForAllHosts, Bunny::NetworkErrorWrapper, Bunny::ChannelAlreadyClosed, Bunny::ConnectionAlreadyClosed, AMQ::Protocol::EmptyResponseError => error @channel.close if @channel.present? raise(Totoro::ConnectionBreakError, "type: #{error.class}, message: #{error.}") end |