Module: Stooge::WorkQueue
- Included in:
- Stooge
- Defined in:
- lib/stooge/work_queue.rb
Instance Method Summary collapse
-
#aenqueue(queue_name, data, headers = {}) ⇒ EM::DefaultDeferrable
Asynchrounous version of enqueue.
-
#enqueue(queue_name, data, headers = {}) ⇒ Object
Push a job onto a named queue.
-
#job(queue, &blk) ⇒ Object
Creates a job handler for a named queue.
Instance Method Details
#aenqueue(queue_name, data, headers = {}) ⇒ EM::DefaultDeferrable
Asynchrounous version of enqueue. Yields when the job has been put onto the queue, if a block is given.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/stooge/work_queue.rb', line 37 def aenqueue(queue_name, data, headers = {}) deferrable = EM::DefaultDeferrable.new with_channel do |channel| = { :routing_key => queue_name, :mandatory => true, :persistent => true, :content_type => 'application/json', :headers => headers } channel.default_exchange.publish(MultiJson.encode(data), ) do Stooge.log("enqueue: #{queue_name}(#{data})") yield if block_given? deferrable.set_deferred_status :succeeded end end deferrable end |
#enqueue(queue_name, data, headers = {}) ⇒ Object
19 20 21 |
# File 'lib/stooge/work_queue.rb', line 19 def enqueue(queue_name, data, headers = {}) EM::Synchrony.sync(aenqueue(queue_name, data, headers)) end |
#job(queue, &blk) ⇒ Object
Creates a job handler for a named queue.
Example:
Stooge.job('example.work') do |args,headers|
# Do the work here...
end
68 69 70 71 72 |
# File 'lib/stooge/work_queue.rb', line 68 def job(queue, &blk) handler = Stooge::Handler.new(queue, :queue_options => { :durable => true }) handler.block = blk add_handler(handler) end |