Class: Fog::Rackspace::Queues::Queue

Inherits:
Model
  • Object
show all
Defined in:
lib/fog/rackspace/models/queues/queue.rb

Instance Attribute Summary collapse

Attributes inherited from Model

#collection, #service

Instance Method Summary collapse

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

#nameString

Returns name of queue.

Returns:



10
# File 'lib/fog/rackspace/models/queues/queue.rb', line 10

identity :name

Instance Method Details

#claimsFog::Rackspace::Queues::Claims

Note:

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

Parameters:

  • ttl (Integer)

    The ttl attribute specifies how long the server waits before releasing the claim. The ttl value must be between 60 and 43200 seconds (12 hours).

  • grace (Integer)

    The grace attribute specifies the message grace period in seconds. The value of grace value must be between 60 and 43200 seconds (12 hours).

  • options (Hash) (defaults to: {})

Yield Parameters:

  • message

    claimed [Fog::Rackspace::Queues::Message]

Returns:

  • (Boolean)

    Returns true if claim was successfully made

Raises:



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, options = {}, &block)
  claim = claims.create(
    options.merge(
    {
      :limit => 1,
      :ttl => ttl,
      :grace => grace
    }))

  if claim
    message = claim.messages.first
    yield message
    message.destroy
    true
  else
    false
  end
end

#destroyBoolean

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

Parameters:

  • body (String, Hash, Array)

    The body attribute specifies an arbitrary document that constitutes the body of the message being sent. The size of this body is limited to 256 KB, excluding whitespace. The document must be valid JSON.

  • ttl (Integer)

    The ttl attribute specifies how long the server waits before releasing the claim. The ttl value must be between 60 and 43200 seconds (12 hours).

  • options (Hash) (defaults to: {})

Returns:

  • (Boolean)

    returns true if message has been succesfully enqueued

Raises:

See Also:



69
70
71
# File 'lib/fog/rackspace/models/queues/queue.rb', line 69

def enqueue(body, ttl, options = {})
  messages.create(options.merge({:body => body, :ttl => ttl}))
end

#messagesFog::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
  @messages ||= begin
    Fog::Rackspace::Queues::Messages.new({
      :service => service,
      :queue => self,
      :client_id => service.client_id,
      :echo => true
    })
  end
end

#saveBoolean

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

#statsHash

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