Class: Droid::WorkerQueue

Inherits:
BaseQueue show all
Defined in:
lib/droid/queue.rb

Instance Attribute Summary collapse

Attributes inherited from BaseQueue

#ex, #mq, #opts, #q, #queue_name

Instance Method Summary collapse

Methods inherited from BaseQueue

#destroy, #log, #tag, #teardown, #temp?

Constructor Details

#initialize(queue_name, opts = {}) ⇒ WorkerQueue

Returns a new instance of WorkerQueue.



75
76
77
78
79
80
# File 'lib/droid/queue.rb', line 75

def initialize(queue_name, opts={})
  @prefetch = opts.delete(:prefetch) || 1
  opts[:auto_delete] = false

  super(queue_name, opts)
end

Instance Attribute Details

#prefetchObject (readonly)

Returns the value of attribute prefetch.



73
74
75
# File 'lib/droid/queue.rb', line 73

def prefetch
  @prefetch
end

Instance Method Details

#setupObject



82
83
84
85
# File 'lib/droid/queue.rb', line 82

def setup
  super
  @mq.prefetch(self.prefetch)
end

#subscribe(amqp_opts = {}, opts = {}) ⇒ Object



87
88
89
90
91
92
93
94
95
96
# File 'lib/droid/queue.rb', line 87

def subscribe(amqp_opts={}, opts={})
  amqp_opts[:ack] = true
  super(amqp_opts, opts) do |request|
    begin
      yield request if block_given?
    ensure
      request.ack unless amqp_opts[:auto_ack] == false
    end
  end
end