class Hat::Worker

Attributes

id[RW]
logger[RW]

Public Class Methods

new(options) click to toggle source
# File lib/hat/worker.rb, line 23
def initialize(options)
  @options    = options
  @connection = Bunny.new
end
queue(name) click to toggle source
# File lib/hat/worker.rb, line 16
def queue(name)
  config.worker.queue.name = name
end

Public Instance Methods

call(delivery_info, properties, payload) click to toggle source
# File lib/hat/worker.rb, line 43
def call(delivery_info, properties, payload)
  config.worker.middlwares.each { |m| delivery_info, properties, payload = m.call(delivery_info, properties, payload) }
end
run() click to toggle source
# File lib/hat/worker.rb, line 32
def run
  logger.debug 'Starting rabbit connection'
  @connection.start
  logger.debug 'Creating channel'
  @channel = @connection.create_channel
  logger.info "Subscribing to #{config.worker.queue.name}"
  queue.subscribe do |delivery_info, properties, payload|
    perform(*call(delivery_info, properties, payload))
  end
end
stop() click to toggle source
# File lib/hat/worker.rb, line 28
def stop
  @stop = true
end

Private Instance Methods

exchange() click to toggle source
# File lib/hat/worker.rb, line 49
def exchange
  @exchange ||= @channel.direct('hat.direct')
end
queue() click to toggle source
# File lib/hat/worker.rb, line 53
def queue
  @queue ||= @channel.queue(config.worker.queue.name).bind(exchange, config.worker.queue.bind_options || {})
end