Class: Fog::Rackspace::Queues::Mock::MockMessage

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

Overview

A single message posted to an in-memory MockQueue.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, queue, client_id, data, ttl) ⇒ MockMessage

Create a new message. Use Fog::Rackspace::Queues::Mock::MockQueue#add_message instead.



193
194
195
196
197
198
# File 'lib/fog/rackspace/queues.rb', line 193

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

Instance Attribute Details

#claimObject

Returns the value of attribute claim.



190
191
192
# File 'lib/fog/rackspace/queues.rb', line 190

def claim
  @claim
end

#createdObject

Returns the value of attribute created.



190
191
192
# File 'lib/fog/rackspace/queues.rb', line 190

def created
  @created
end

#dataObject

Returns the value of attribute data.



189
190
191
# File 'lib/fog/rackspace/queues.rb', line 189

def data
  @data
end

#idObject

Returns the value of attribute id.



189
190
191
# File 'lib/fog/rackspace/queues.rb', line 189

def id
  @id
end

#producer_idObject

Returns the value of attribute producer_id.



189
190
191
# File 'lib/fog/rackspace/queues.rb', line 189

def producer_id
  @producer_id
end

#queueObject

Returns the value of attribute queue.



189
190
191
# File 'lib/fog/rackspace/queues.rb', line 189

def queue
  @queue
end

#ttlObject

Returns the value of attribute ttl.



189
190
191
# File 'lib/fog/rackspace/queues.rb', line 189

def ttl
  @ttl
end

Instance Method Details

#ageInteger

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

Returns:

  • (Integer)


203
204
205
# File 'lib/fog/rackspace/queues.rb', line 203

def age
  Time.now.to_i - @created
end

#claimed?Boolean

Return true if this message has been claimed.

Returns:

  • (Boolean)


217
218
219
# File 'lib/fog/rackspace/queues.rb', line 217

def claimed?
  ! @claim.nil?
end

#expired?Boolean

Determine if this message has lived longer than its designated ttl.

Returns:

  • (Boolean)


224
225
226
# File 'lib/fog/rackspace/queues.rb', line 224

def expired?
  age > ttl
end

#extend_lifeObject

Extend the #ttl of this message to include the lifetime of the claim it belongs to, plus the claim’s grace period.



230
231
232
233
234
# File 'lib/fog/rackspace/queues.rb', line 230

def extend_life
  return unless @claim
  extended = claim.message_end_of_life - @created
  @ttl = extended if extended > @ttl
end

#hrefString

Generate a URI segment that identifies this message.

Returns:



210
211
212
# File 'lib/fog/rackspace/queues.rb', line 210

def href
  "#{PATH_BASE}/#{@queue.name}/messages/#{@id}"
end

#to_hHash

Convert this message to a GET payload.

Returns:



239
240
241
242
243
244
245
246
# File 'lib/fog/rackspace/queues.rb', line 239

def to_h
  {
    "body" => @data,
    "age" => age,
    "ttl" => @ttl,
    "href" => href
  }
end