Class: Hat::Worker

Inherits:
Object
  • Object
show all
Includes:
Configurable
Defined in:
lib/hat/worker.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Configurable

#config, included

Constructor Details

#initialize(options) ⇒ Worker

Returns a new instance of Worker.



23
24
25
26
# File 'lib/hat/worker.rb', line 23

def initialize(options)
  @options    = options
  @connection = Bunny.new
end

Instance Attribute Details

#idObject

Returns the value of attribute id.



5
6
7
# File 'lib/hat/worker.rb', line 5

def id
  @id
end

#loggerObject

Returns the value of attribute logger.



5
6
7
# File 'lib/hat/worker.rb', line 5

def logger
  @logger
end

Class Method Details

.queue(name) ⇒ Object



16
17
18
# File 'lib/hat/worker.rb', line 16

def queue(name)
  config.worker.queue.name = name
end

Instance Method Details

#call(delivery_info, properties, payload) ⇒ Object



43
44
45
# 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

#runObject



32
33
34
35
36
37
38
39
40
41
# 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

#stopObject



28
29
30
# File 'lib/hat/worker.rb', line 28

def stop
  @stop = true
end