class Fog::Rackspace::Queues::Mock::MockClaim
Reservation indicating that a consumer is in the process of handling a collection of messages from a queue.
Attributes
Public Class Methods
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 266 def initialize(queue, ttl, grace) @queue = queue @id = Fog::Mock.random_hex(24) @ttl, @grace = ttl, grace touch! end
Public Instance Methods
Determine how long ago this claim was created, in seconds.
@return [Integer]
# File lib/fog/rackspace/queues.rb, line 288 def age Time.now.to_i - @created end
Determine if this claim has lasted longer than its designated ttl.
@return [Boolean]
# File lib/fog/rackspace/queues.rb, line 295 def expired? age > ttl end
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 281 def message_end_of_life @created + @ttl + @grace end
Access the collection of messages owned by this claim.
@return [Array<Message>]
# File lib/fog/rackspace/queues.rb, line 302 def messages @queue.messages.select { |m| m.claim == self } end
Convert this claim into a GET payload.
@return [Hash]
# File lib/fog/rackspace/queues.rb, line 309 def to_h ms = messages.map { |m| m.to_h } { "age" => age, "href" => "#{PATH_BASE}/#{@queue.name}/claims/#{@id}", "ttl" => @ttl, "messages" => ms } end
Set or reset the creation time of the claim to the present.
# File lib/fog/rackspace/queues.rb, line 274 def touch! @created = Time.now.to_i end