Class: JobQueue::AMQPAdapter
- Inherits:
-
Object
- Object
- JobQueue::AMQPAdapter
- Defined in:
- lib/job_queue/adapters/amqp_adapter.rb
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ AMQPAdapter
constructor
A new instance of AMQPAdapter.
- #put(string) ⇒ Object
- #subscribe(error_report, &block) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ AMQPAdapter
Returns a new instance of AMQPAdapter.
4 5 6 7 8 9 |
# File 'lib/job_queue/adapters/amqp_adapter.rb', line 4 def initialize( = {}) amq = MQ.new @exchange = amq.direct('photo', :durable => true) @queue = amq.queue('photo_worker', :durable => true) @queue.bind(@exchange) end |
Instance Method Details
#put(string) ⇒ Object
11 12 13 |
# File 'lib/job_queue/adapters/amqp_adapter.rb', line 11 def put(string) @queue.publish(string, :persistent => true) end |
#subscribe(error_report, &block) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/job_queue/adapters/amqp_adapter.rb', line 15 def subscribe(error_report, &block) EM.add_periodic_timer(0) do begin @queue.pop do |header, body| next unless body JobQueue.logger.info "AMQP received #{body}" yield body end rescue => e error_report.call(job.body, e) end end end |