Parent

Class/Module Index [+]

Quicksearch

Fog::Rackspace::Queues::Mock::MockClaim

Reservation indicating that a consumer is in the process of handling a collection of messages from a queue.

Attributes

grace[RW]
id[RW]
queue[RW]
ttl[RW]

Public Class Methods

new(queue, ttl, grace) click to toggle source

Create a new MockClaim. Clients should use {MockQueue#add_claim} instead.

@param queue [MockQueue] The queue that owns this claim. @param ttl [Integer] Duration, in seconds, that this queue should last. @param grace [Integer] Extra life granted to messages within this claim after this

claim expires, to give another consumer a chance to process it.
# File lib/fog/rackspace/queues.rb, line 259
def initialize(queue, ttl, grace)
  @queue = queue
  @id = Fog::Mock.random_hex(24)
  @ttl, @grace = ttl, grace
  touch!
end

Public Instance Methods

age() click to toggle source

Determine how long ago this claim was created, in seconds.

@return [Integer]

# File lib/fog/rackspace/queues.rb, line 281
def age
  Time.now.to_i - @created
end
expired?() click to toggle source

Determine if this claim has lasted longer than its designated ttl.

@return [Boolean]

# File lib/fog/rackspace/queues.rb, line 288
def expired?
  age > ttl
end
message_end_of_life() click to toggle source

Calculate the time at which messages belonging to this claim should expire.

@return [Integer] Seconds since the epoch.

# File lib/fog/rackspace/queues.rb, line 274
def message_end_of_life
  @created + @ttl + @grace
end
messages() click to toggle source

Access the collection of messages owned by this claim.

@return [Array<Message>]

# File lib/fog/rackspace/queues.rb, line 295
def messages
  @queue.messages.select { |m| m.claim == self }
end
to_h() click to toggle source

Convert this claim into a GET payload.

@return [Hash]

# File lib/fog/rackspace/queues.rb, line 302
def to_h
  ms = messages.map { |m| m.to_h }

  {
    "age" => age,
    "href" => "#{PATH_BASE}/#{@queue.name}/claims/#{@id}",
    "ttl" => @ttl,
    "messages" => ms
  }
end
touch!() click to toggle source

Set or reset the creation time of the claim to the present.

# File lib/fog/rackspace/queues.rb, line 267
def touch!
  @created = Time.now.to_i
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.