Class: Hat::Worker
Instance Attribute Summary collapse
-
#id ⇒ Object
Returns the value of attribute id.
-
#logger ⇒ Object
Returns the value of attribute logger.
Class Method Summary collapse
Instance Method Summary collapse
- #call(delivery_info, properties, payload) ⇒ Object
-
#initialize(options) ⇒ Worker
constructor
A new instance of Worker.
- #run ⇒ Object
- #stop ⇒ Object
Methods included from Configurable
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 = @connection = Bunny.new end |
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
5 6 7 |
# File 'lib/hat/worker.rb', line 5 def id @id end |
#logger ⇒ Object
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 |
#run ⇒ Object
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 |
#stop ⇒ Object
28 29 30 |
# File 'lib/hat/worker.rb', line 28 def stop @stop = true end |