Class: Fog::Rackspace::Queues::Mock::MockClaim
- Inherits:
-
Object
- Object
- Fog::Rackspace::Queues::Mock::MockClaim
- Defined in:
- lib/fog/rackspace/queues.rb
Overview
Reservation indicating that a consumer is in the process of handling a collection of messages from a queue.
Instance Attribute Summary collapse
-
#grace ⇒ Object
Returns the value of attribute grace.
-
#id ⇒ Object
Returns the value of attribute id.
-
#queue ⇒ Object
Returns the value of attribute queue.
-
#ttl ⇒ Object
Returns the value of attribute ttl.
Instance Method Summary collapse
-
#age ⇒ Integer
Determine how long ago this claim was created, in seconds.
-
#expired? ⇒ Boolean
Determine if this claim has lasted longer than its designated ttl.
-
#initialize(queue, ttl, grace) ⇒ MockClaim
constructor
Create a new MockClaim.
-
#message_end_of_life ⇒ Integer
Calculate the time at which messages belonging to this claim should expire.
-
#messages ⇒ Array<Message>
Access the collection of messages owned by this claim.
-
#to_h ⇒ Hash
Convert this claim into a GET payload.
-
#touch! ⇒ Object
Set or reset the creation time of the claim to the present.
Constructor Details
#initialize(queue, ttl, grace) ⇒ MockClaim
Create a new MockClaim. Clients should use Fog::Rackspace::Queues::Mock::MockQueue#add_claim instead.
266 267 268 269 270 271 |
# 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 |
Instance Attribute Details
#grace ⇒ Object
Returns the value of attribute grace.
258 259 260 |
# File 'lib/fog/rackspace/queues.rb', line 258 def grace @grace end |
#id ⇒ Object
Returns the value of attribute id.
258 259 260 |
# File 'lib/fog/rackspace/queues.rb', line 258 def id @id end |
#queue ⇒ Object
Returns the value of attribute queue.
258 259 260 |
# File 'lib/fog/rackspace/queues.rb', line 258 def queue @queue end |
#ttl ⇒ Object
Returns the value of attribute ttl.
258 259 260 |
# File 'lib/fog/rackspace/queues.rb', line 258 def ttl @ttl end |
Instance Method Details
#age ⇒ Integer
Determine how long ago this claim was created, in seconds.
288 289 290 |
# File 'lib/fog/rackspace/queues.rb', line 288 def age Time.now.to_i - @created end |
#expired? ⇒ Boolean
Determine if this claim has lasted longer than its designated ttl.
295 296 297 |
# File 'lib/fog/rackspace/queues.rb', line 295 def expired? age > ttl end |
#message_end_of_life ⇒ Integer
Calculate the time at which messages belonging to this claim should expire.
281 282 283 |
# File 'lib/fog/rackspace/queues.rb', line 281 def @created + @ttl + @grace end |
#messages ⇒ Array<Message>
Access the collection of messages owned by this claim.
302 303 304 |
# File 'lib/fog/rackspace/queues.rb', line 302 def @queue..select { |m| m.claim == self } end |
#to_h ⇒ Hash
Convert this claim into a GET payload.
309 310 311 312 313 314 315 316 317 318 |
# File 'lib/fog/rackspace/queues.rb', line 309 def to_h ms = .map { |m| m.to_h } { "age" => age, "href" => "#{PATH_BASE}/#{@queue.name}/claims/#{@id}", "ttl" => @ttl, "messages" => ms } end |
#touch! ⇒ Object
Set or reset the creation time of the claim to the present.
274 275 276 |
# File 'lib/fog/rackspace/queues.rb', line 274 def touch! @created = Time.now.to_i end |