A single message posted to an in-memory MockQueue.
Create a new message. Use {MockQueue#add_message} instead.
# File lib/fog/rackspace/queues.rb, line 192 def initialize(id, queue, client_id, data, ttl) @id, @queue, @producer_id = id, queue, client_id @data, @ttl = data, ttl @created = Time.now.to_i @claim = nil end
Determine how long ago this message was created, in seconds.
@return [Integer]
# File lib/fog/rackspace/queues.rb, line 202 def age Time.now.to_i - @created end
Return true if this message has been claimed.
@return [Boolean]
# File lib/fog/rackspace/queues.rb, line 216 def claimed? ! @claim.nil? end
Determine if this message has lived longer than its designated ttl.
@return [Boolean]
# File lib/fog/rackspace/queues.rb, line 223 def expired? age > ttl end
Extend the {#ttl} of this message to include the lifetime of the claim it belongs to, plus the claim's grace period.
# File lib/fog/rackspace/queues.rb, line 229 def extend_life return unless @claim extended = claim.message_end_of_life - @created @ttl = extended if extended > @ttl end
Generate a URI segment that identifies this message.
@return [String]
# File lib/fog/rackspace/queues.rb, line 209 def href "#{PATH_BASE}/#{@queue.name}/messages/#{@id}" end
Convert this message to a GET payload.
@return [Hash]
# File lib/fog/rackspace/queues.rb, line 238 def to_h { "body" => @data, "age" => age, "ttl" => @ttl, "href" => href } end