Class: Fog::Rackspace::Queues::Queue
- Defined in:
- lib/fog/rackspace/models/queues/queue.rb
Instance Attribute Summary collapse
-
#name ⇒ String
Name of queue.
Attributes inherited from Model
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.
Methods inherited from Model
#initialize, #inspect, #reload, #symbolize_keys, #to_json, #wait_for
Methods included from Attributes::ClassMethods
#_load, #aliases, #attribute, #attributes, #identity, #ignore_attributes, #ignored_attributes
Methods included from Core::DeprecatedConnectionAccessors
#connection, #connection=, #prepare_service_value
Methods included from Attributes::InstanceMethods
#_dump, #attributes, #dup, #identity, #identity=, #merge_attributes, #new_record?, #persisted?, #requires, #requires_one
Constructor Details
This class inherits a constructor from Fog::Model
Instance Attribute Details
#name ⇒ String
Returns name of queue.
10 |
# File 'lib/fog/rackspace/models/queues/queue.rb', line 10 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.
49 50 51 52 53 54 55 56 |
# File 'lib/fog/rackspace/models/queues/queue.rb', line 49 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
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/fog/rackspace/models/queues/queue.rb', line 84 def dequeue(ttl, grace, = {}, &block) claim = claims.create( .merge( { :limit => 1, :ttl => ttl, :grace => grace })) if claim = claim..first yield .destroy true else false end end |
#destroy ⇒ Boolean
Destroys queue
128 129 130 131 132 |
# File 'lib/fog/rackspace/models/queues/queue.rb', line 128 def destroy requires :name service.delete_queue(name) true end |
#enqueue(body, ttl, options = {}) ⇒ Boolean
Helper method to enqueue a single message
69 70 71 |
# File 'lib/fog/rackspace/models/queues/queue.rb', line 69 def enqueue(body, ttl, = {}) .create(.merge({:body => body, :ttl => ttl})) end |
#messages ⇒ Fog::Rackspace::Queues::Messages
Returns list of messages in the queue
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/fog/rackspace/models/queues/queue.rb', line 19 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
113 114 115 116 117 |
# File 'lib/fog/rackspace/models/queues/queue.rb', line 113 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.
37 38 39 |
# File 'lib/fog/rackspace/models/queues/queue.rb', line 37 def stats service.get_queue_stats(name).body['messages'] end |