33 lines
716 B
Ruby
33 lines
716 B
Ruby
# frozen_string_literal: true
|
|
|
|
require_relative '../../amqp/amqp_service'
|
|
|
|
module SchedulePipeline
|
|
module Queue
|
|
class BunnyQueue
|
|
def initialize(destination)
|
|
@destination = destination
|
|
end
|
|
|
|
def push(msg)
|
|
amqp.default_exchange.publish(msg.to_json, routing_key: @destination)
|
|
end
|
|
|
|
def subscribe(&block)
|
|
amqp_queue.subscribe do |_delivery_info, _metadata, payload|
|
|
block.call(JSON.parse(payload).with_indifferent_access)
|
|
end
|
|
end
|
|
|
|
private
|
|
def amqp
|
|
Amqp::AmqpService.instance
|
|
end
|
|
|
|
def amqp_queue
|
|
@queue ||= amqp.queue(@destination.to_s, auto_delete: false, durable: true)
|
|
end
|
|
end
|
|
end
|
|
end
|