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


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.

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

Yield Parameters:

  • message

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

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


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


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.


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

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