Class: Fog::Rackspace::Queues::Queue
- Inherits:
-
Model
- Object
- Model
- Fog::Rackspace::Queues::Queue
- Defined in:
- lib/fog/rackspace/models/queues/queue.rb
Instance Attribute Summary collapse
-
#name ⇒ String
Name of queue.
Instance Method Summary collapse
-
#claims ⇒ Fog::Rackspace::Queues::Claims
Returns list of claims as they are created.
-
#dequeue(ttl, grace, options = {}) {|message| ... } ⇒ Boolean
Helper method to claim (dequeue) a single message, yield the message, and then destroy it.
-
#destroy ⇒ Boolean
Destroys queue.
-
#enqueue(body, ttl, options = {}) ⇒ Boolean
Helper method to enqueue a single message.
-
#messages ⇒ Fog::Rackspace::Queues::Messages
Returns list of messages in the queue.
-
#save ⇒ Boolean
Creates queue Requires name attribute to be populated.
-
#stats ⇒ Hash
Returns queue statistics, including how many messages are in the queue, categorized by status.
Instance Attribute Details
#name ⇒ String
Returns name of queue.
9 |
# File 'lib/fog/rackspace/models/queues/queue.rb', line 9 identity :name |
Instance Method Details
#claims ⇒ Fog::Rackspace::Queues::Claims
The Rackspace Cloud does not currently provide a way to retrieve claims as such this list is maintained by fog. Claims are added to the claim collection
Returns list of claims as they are created.
48 49 50 51 52 53 54 55 |
# File 'lib/fog/rackspace/models/queues/queue.rb', line 48 def claims @claims ||= begin Fog::Rackspace::Queues::Claims.new({ :service => service, :queue => self }) end end |
#dequeue(ttl, grace, options = {}) {|message| ... } ⇒ Boolean
Helper method to claim (dequeue) a single message, yield the message, and then destroy it
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/fog/rackspace/models/queues/queue.rb', line 83 def dequeue(ttl, grace, = {}, &block) claim = claims.create( .merge( { :limit => 1, :ttl => ttl, :grace => grace })) if claim = claim..first yield if block_given? .destroy true else false end end |
#destroy ⇒ Boolean
Destroys queue
127 128 129 130 131 |
# File 'lib/fog/rackspace/models/queues/queue.rb', line 127 def destroy requires :name service.delete_queue(name) true end |
#enqueue(body, ttl, options = {}) ⇒ Boolean
Helper method to enqueue a single message
68 69 70 |
# File 'lib/fog/rackspace/models/queues/queue.rb', line 68 def enqueue(body, ttl, = {}) .create(.merge({:body => body, :ttl => ttl})) end |
#messages ⇒ Fog::Rackspace::Queues::Messages
Returns list of messages in the queue
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/fog/rackspace/models/queues/queue.rb', line 18 def @messages ||= begin Fog::Rackspace::Queues::Messages.new({ :service => service, :queue => self, :client_id => service.client_id, :echo => true }) end end |
#save ⇒ Boolean
Creates queue Requires name attribute to be populated
112 113 114 115 116 |
# File 'lib/fog/rackspace/models/queues/queue.rb', line 112 def save requires :name data = service.create_queue(name) true end |
#stats ⇒ Hash
Returns queue statistics, including how many messages are in the queue, categorized by status.
36 37 38 |
# File 'lib/fog/rackspace/models/queues/queue.rb', line 36 def stats service.get_queue_stats(name).body['messages'] end |