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.



199
200
201
202
203
204
# File 'lib/fog/rackspace/queues.rb', line 199

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.



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

def claim
  @claim
end

#createdObject

Returns the value of attribute created.



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

def created
  @created
end

#dataObject

Returns the value of attribute data.



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

def data
  @data
end

#idObject

Returns the value of attribute id.



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

def id
  @id
end

#producer_idObject

Returns the value of attribute producer_id.



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

def producer_id
  @producer_id
end

#queueObject

Returns the value of attribute queue.



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

def queue
  @queue
end

#ttlObject

Returns the value of attribute ttl.



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

def ttl
  @ttl
end

Instance Method Details

#ageInteger

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

Returns:

  • (Integer)


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

def age
  Time.now.to_i - @created
end

#claimed?Boolean

Return true if this message has been claimed.

Returns:

  • (Boolean)


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

def claimed?
  ! @claim.nil?
end

#expired?Boolean

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

Returns:

  • (Boolean)


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

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.



236
237
238
239
240
# File 'lib/fog/rackspace/queues.rb', line 236

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:



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

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

#to_hHash

Convert this message to a GET payload.

Returns:



245
246
247
248
249
250
251
252
# File 'lib/fog/rackspace/queues.rb', line 245

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