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

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#nameString

Returns name of queue.

Returns:

  • (String)

    name of queue



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

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.

Returns:

Raises:



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

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:



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

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

#destroyBoolean

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

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:



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

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



18
19
20
21
22
23
24
25
26
27
# File 'lib/fog/rackspace/models/queues/queue.rb', line 18

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

Returns:

  • (Boolean)

    returns true if queue has been succesfully saved

Raises:

See Also:



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

#statsHash

Returns queue statistics, including how many messages are in the queue, categorized by status.

Returns:

  • (Hash)

    Retrieves a collection of messages.

Raises:

See Also:



36
37
38
# File 'lib/fog/rackspace/models/queues/queue.rb', line 36

def stats
  service.get_queue_stats(name).body['messages']
end