Class: Fog::Rackspace::Queues::Claim

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

Instance Attribute Summary collapse

Attributes inherited from Model

#collection, #service

Instance Method Summary collapse

Methods inherited from Model

#inspect, #reload, #symbolize_keys, #to_json, #wait_for

Methods included from Attributes::ClassMethods

#_load, #aliases, #attribute, #attributes, #ignore_attributes, #ignored_attributes

Methods included from Core::DeprecatedConnectionAccessors

#connection, #connection=, #prepare_service_value

Methods included from Attributes::InstanceMethods

#_dump, #attributes, #dup, #identity=, #merge_attributes, #new_record?, #persisted?, #requires, #requires_one

Constructor Details

#initialize(new_attributes = {}) ⇒ Claim

Returns a new instance of Claim.



97
98
99
100
101
102
103
# File 'lib/fog/rackspace/models/queues/claim.rb', line 97

def initialize(new_attributes = {})
  # A hack in support of the #messages= hack up above. #messages= requires #collection to
  # be populated first to succeed, which is always the case in modern Rubies that preserve
  # Hash ordering, but not in 1.8.7.
  @collection = new_attributes.delete(:collection)
  super(new_attributes)
end

Instance Attribute Details

#graceInteger

Returns The grace attribute specifies the message grace period in seconds. The value of grace value must be between 60 and 43200 seconds (12 hours). You must include a value for this attribute in your request. To deal with workers that have stopped responding (for up to 1209600 seconds or 14 days, including claim lifetime), the server extends the lifetime of claimed messages to be at least as long as the lifetime of the claim itself, plus the specified grace period. If a claimed message would normally live longer than the grace period, its expiration is not adjusted.

Returns:

  • (Integer)

    The grace attribute specifies the message grace period in seconds. The value of grace value must be between 60 and 43200 seconds (12 hours). You must include a value for this attribute in your request. To deal with workers that have stopped responding (for up to 1209600 seconds or 14 days, including claim lifetime), the server extends the lifetime of claimed messages to be at least as long as the lifetime of the claim itself, plus the specified grace period. If a claimed message would normally live longer than the grace period, its expiration is not adjusted.



17
# File 'lib/fog/rackspace/models/queues/claim.rb', line 17

attribute :grace

#identityString (readonly) Also known as: id

Returns The claim’s id.

Returns:

  • (String)

    The claim’s id



10
# File 'lib/fog/rackspace/models/queues/claim.rb', line 10

identity :identity

#limitArray<Fog::Rackspace::Queues::Messages>, Array<Strings>

Returns Specifies the number of messages to return, up to 20 messages. If limit is not specified, limit defaults to 10.

Returns:

  • (Array<Fog::Rackspace::Queues::Messages>, Array<Strings>)

    Specifies the number of messages to return, up to 20 messages. If limit is not specified, limit defaults to 10.



25
# File 'lib/fog/rackspace/models/queues/claim.rb', line 25

attribute :limit

#ttlInteger

Returns The ttl attribute specifies how long the server waits before releasing the claim. The ttl value must be between 60 and 43200 seconds (12 hours).

Returns:

  • (Integer)

    The ttl attribute specifies how long the server waits before releasing the claim. The ttl value must be between 60 and 43200 seconds (12 hours).



21
# File 'lib/fog/rackspace/models/queues/claim.rb', line 21

attribute :ttl

Instance Method Details

#destroyBoolean

Destroys Claim



61
62
63
64
65
66
67
68
69
70
# File 'lib/fog/rackspace/models/queues/claim.rb', line 61

def destroy
  requires :identity, :queue
  service.delete_claim(queue.name, identity)

  #Since Claims aren't a server side collection, we should remove
  # the claim from the collection.
  collection.delete(self)

  true
end

#messages=(messages) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/fog/rackspace/models/queues/claim.rb', line 72

def messages=(messages)
  #HACK - Models require a collection, but I don't really want to expose
  # the messages collection to users here.
  message_collection = Fog::Rackspace::Queues::Messages.new({
      :service => service,
      :queue => queue,
      :client_id => service.client_id,
      :echo => true
    })
  attributes[:messages] = messages.collect do |message|
    if message.instance_of? Fog::Rackspace::Queues::Message
      message.claim_id = self.id
      message
    else
      Fog::Rackspace::Queues::Message.new(
        message.merge({
          :service => service,
          :collection => message_collection,
          :claim_id => self.id
        }.merge(message))
      )
    end
  end
end

#saveBoolean

Creates or updates a claim



44
45
46
47
48
49
50
# File 'lib/fog/rackspace/models/queues/claim.rb', line 44

def save
  if identity.nil?
    create
  else
    update
  end
end