Module: Sinatra::Queue::ClassMethods
- Defined in:
- lib/sinatra/queue.rb
Instance Method Summary collapse
-
#consume_queue(queue_name, &block) ⇒ Object
Register a handler for a queue.
- #queue_consumers ⇒ Object
Instance Method Details
#consume_queue(queue_name, &block) ⇒ Object
Register a handler for a queue.
consume_queue 'jobs' do |batch|
batch.messages.each { |m| ...; m.ack }
end
43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/sinatra/queue.rb', line 43 def consume_queue(queue_name, &block) raise ArgumentError, 'consume_queue requires a block' unless block qname = queue_name.to_s raise ArgumentError, 'queue_name must be non-empty' if qname.empty? method_name = "__queue_handler_#{qname.gsub(/[^A-Za-z0-9_]/, '_')}".to_sym ::Cloudflare::QueueContext.send(:define_method, method_name, &block) unbound = ::Cloudflare::QueueContext.instance_method(method_name) ::Cloudflare::QueueContext.send(:remove_method, method_name) queue_consumers[qname] = unbound ::Cloudflare::QueueConsumer.register(qname, unbound) nil end |
#queue_consumers ⇒ Object
34 35 36 |
# File 'lib/sinatra/queue.rb', line 34 def queue_consumers @queue_consumers ||= {} end |