class Fog::Rackspace::Queues::Real

Public Class Methods

new(options = {}) click to toggle source
# File lib/fog/rackspace/queues.rb, line 381
def initialize(options = {})
  apply_options(options)

  authenticate

  @persistent = options[:persistent] || false
  @connection = Fog::Core::Connection.new(endpoint_uri.to_s, @persistent, @connection_options)
end

Public Instance Methods

create_claim(queue_name, ttl, grace, options = {}) click to toggle source

This operation claims a set of messages (up to the value of the limit parameter) from oldest to newest and skips any messages that are already claimed. If no unclaimed messages are available, the API returns a 204 No Content message.

@param [String] queue_name Specifies the name of the queue. @param [Integer] ttl 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). @param [Integer] grace The grace attribute specifies the message grace period in seconds. The value of grace value must be between 60 and 43200 seconds (12 hours). @param [Hash] options @option options [Integer] :limit - Specifies the number of messages to return, up to 20 messages. If limit is not specified, limit defaults to 10. @return [Excon::Response] response @raise [Fog::Rackspace::Queues::NotFound] - HTTP 404 @raise [Fog::Rackspace::Queues::BadRequest] - HTTP 400 @raise [Fog::Rackspace::Queues::InternalServerError] - HTTP 500 @raise [Fog::Rackspace::Queues::ServiceError] @see docs.rackspace.com/queues/api/v1.0/cq-devguide/content/POST_claimMessages__version__queues__queue_name__claims_claims-operations-dle001.html

# File lib/fog/rackspace/requests/queues/create_claim.rb, line 19
def create_claim(queue_name, ttl, grace, options = {})
  body = {
    :ttl => ttl,
    :grace => grace
  }

  query = {}
  query[:limit] = options[:limit] if options.key? :limit
  request(
    :body => Fog::JSON.encode(body),
    :expects => [200, 201, 204],
    :method => 'POST',
    :path => "queues/#{queue_name}/claims",
    :query => query
  )
end
create_message(client_id, queue_name, body, ttl) click to toggle source

This operation posts the specified message or messages. @note You can submit up to 10 messages in a single request.

@param [String] client_id UUID for the client instance. @param [String] queue_name Specifies the name of the queue. @param [String, Hash, Array] body The body attribute specifies an arbitrary document that constitutes the body of the message being sent.

The size of this body is limited to 256 KB, excluding whitespace. The document must be valid JSON.

@param [Integer] ttl 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). @return [Excon::Response] response @raise [Fog::Rackspace::Queues::NotFound] - HTTP 404 @raise [Fog::Rackspace::Queues::BadRequest] - HTTP 400 @raise [Fog::Rackspace::Queues::InternalServerError] - HTTP 500 @raise [Fog::Rackspace::Queues::ServiceError] @see docs.rackspace.com/queues/api/v1.0/cq-devguide/content/POST_postMessage__version__queues__queue_name__messages_message-operations-dle001.html

# File lib/fog/rackspace/requests/queues/create_message.rb, line 19
def create_message(client_id, queue_name, body, ttl)
  data = [{
    :ttl => ttl,
    :body => body
  }]
  request(
    :body => Fog::JSON.encode(data),
    :expects => 201,
    :method => 'POST',
    :path => "queues/#{queue_name}/messages",
    :headers => { 'Client-ID' => client_id }
  )
end
create_queue(queue_name) click to toggle source

This operation creates a new queue. The body of the request is empty.

@param [String] queue_name Specifies the name of the queue. @return [Excon::Response] response @raise [Fog::Rackspace::Queues::NotFound] - HTTP 404 @raise [Fog::Rackspace::Queues::BadRequest] - HTTP 400 @raise [Fog::Rackspace::Queues::InternalServerError] - HTTP 500 @raise [Fog::Rackspace::Queues::ServiceError] @see docs.rackspace.com/queues/api/v1.0/cq-devguide/content/PUT_createQueue__version__queues__queue_name__queue-operations-dle001.html

# File lib/fog/rackspace/requests/queues/create_queue.rb, line 15
def create_queue(queue_name)
  request(
    :body => Fog::JSON.encode({}),
    :expects => 201,
    :method => 'PUT',
    :path => "queues/#{queue_name}"
  )
end
delete_claim(queue_name, claim_id) click to toggle source

This operation immediately releases a claim, making any remaining, undeleted) messages that are associated with the claim available to other workers. Claims with malformed IDs or claims that are not found by ID are ignored.

@param [String] queue_name Specifies the name of the queue. @param [String] claim_id Specifies the claim ID. @return [Excon::Response] response @raise [Fog::Rackspace::Queues::NotFound] - HTTP 404 @raise [Fog::Rackspace::Queues::BadRequest] - HTTP 400 @raise [Fog::Rackspace::Queues::InternalServerError] - HTTP 500 @raise [Fog::Rackspace::Queues::ServiceError] @see docs.rackspace.com/queues/api/v1.0/cq-devguide/content/DELETE_deleteClaim__version__queues_queue_name_claims__claimId__claims-operations-dle001.html

# File lib/fog/rackspace/requests/queues/delete_claim.rb, line 16
def delete_claim(queue_name, claim_id)
  request(
    :expects => 204,
    :method => 'DELETE',
    :path => "queues/#{queue_name}/claims/#{claim_id}"
  )
end
delete_message(queue_name, message_id, options = {}) click to toggle source

This operation immediately deletes the specified message. @note If you do not specify claim_id, but the message is claimed, the operation fails. You can only delete claimed messages by providing an appropriate claim_id.

@param [String] queue_name Specifies the name of the queue. @param [String] message_id Specifies the message ID. @param [Hash] options @option options [Integer] :claim_id - Identifies the claim. @return [Excon::Response] response @raise [Fog::Rackspace::Queues::NotFound] - HTTP 404 @raise [Fog::Rackspace::Queues::BadRequest] - HTTP 400 @raise [Fog::Rackspace::Queues::InternalServerError] - HTTP 500 @raise [Fog::Rackspace::Queues::ServiceError] @see docs.rackspace.com/queues/api/v1.0/cq-devguide/content/DELETE_deleteMessage__version__queues_queue_name_messages__messageId__message-operations-dle001.html

# File lib/fog/rackspace/requests/queues/delete_message.rb, line 18
def delete_message(queue_name, message_id, options = {})
  query = {}
  query[:claim_id] = options[:claim_id] if options.key? :claim_id
  request(
    :expects => 204,
    :method => 'DELETE',
    :path => "queues/#{queue_name}/messages/#{message_id}",
    :query => query
  )
end
delete_queue(queue_name) click to toggle source

This operation immediately deletes a queue and all of its existing messages.

@param [String] queue_name Specifies the name of the queue. @return [Excon::Response] response @raise [Fog::Rackspace::Queues::NotFound] - HTTP 404 @raise [Fog::Rackspace::Queues::BadRequest] - HTTP 400 @raise [Fog::Rackspace::Queues::InternalServerError] - HTTP 500 @raise [Fog::Rackspace::Queues::ServiceError] @see docs.rackspace.com/queues/api/v1.0/cq-devguide/content/DELETE_deleteQueue__version__queues__queue_name__queue-operations-dle001.html

# File lib/fog/rackspace/requests/queues/delete_queue.rb, line 14
def delete_queue(queue_name)
  request(
    :expects => 204,
    :method => 'DELETE',
    :path => "queues/#{queue_name}"
  )
end
get_claim(queue_name, claim_id) click to toggle source

This operation queries the specified claim for the specified queue. Claims with malformed IDs or claims that are not found by ID are ignored.

@param [String] queue_name Specifies the name of the queue. @param [Integer] claim_id Specifies the claim ID. @return [Excon::Response] response @raise [Fog::Rackspace::Queues::NotFound] - HTTP 404 @raise [Fog::Rackspace::Queues::BadRequest] - HTTP 400 @raise [Fog::Rackspace::Queues::InternalServerError] - HTTP 500 @raise [Fog::Rackspace::Queues::ServiceError] @see docs.rackspace.com/queues/api/v1.0/cq-devguide/content/GET_queryClaim__version__queues_queue_name_claims__claimId__claims-operations-dle001.html

# File lib/fog/rackspace/requests/queues/get_claim.rb, line 15
def get_claim(queue_name, claim_id)
  request(
    :expects => 200,
    :method => 'GET',
    :path => "queues/#{queue_name}/claims/#{claim_id}"
  )
end
get_message(client_id, queue_name, message_id) click to toggle source

This operation gets the specified message from the specified queue.

@param [String] client_id UUID for the client instance. @param [String] queue_name Specifies the name of the queue. @param [Integer] message_id Specifies the message ID. @return [Excon::Response] response @raise [Fog::Rackspace::Queues::NotFound] - HTTP 404 @raise [Fog::Rackspace::Queues::BadRequest] - HTTP 400 @raise [Fog::Rackspace::Queues::InternalServerError] - HTTP 500 @raise [Fog::Rackspace::Queues::ServiceError] @see docs.rackspace.com/queues/api/v1.0/cq-devguide/content/GET_getSpecificMessage__version__queues_queue_name_messages__messageId__message-operations-dle001.html

# File lib/fog/rackspace/requests/queues/get_message.rb, line 16
def get_message(client_id, queue_name, message_id)
  request(
    :expects => 200,
    :method => 'GET',
    :path => "queues/#{queue_name}/messages/#{message_id}",
    :headers => { 'Client-ID' => client_id }
  )
end
get_queue(queue_name) click to toggle source

This operation verifies whether the specified queue exists.

@param [String] queue_name Specifies the name of the queue. @return [Excon::Response] response @raise [Fog::Rackspace::Queues::NotFound] - HTTP 404 @raise [Fog::Rackspace::Queues::BadRequest] - HTTP 400 @raise [Fog::Rackspace::Queues::InternalServerError] - HTTP 500 @raise [Fog::Rackspace::Queues::ServiceError] @see docs.rackspace.com/queues/api/v1.0/cq-devguide/content/GET_checkQueueExists__version__queues__queue_name__queue-operations-dle001.html

# File lib/fog/rackspace/requests/queues/get_queue.rb, line 14
def get_queue(queue_name)
  request(
    :expects => [200, 204],
    :method => 'GET',
    :path => "queues/#{queue_name}"
  )
end
get_queue_stats(queue_name) click to toggle source

This operation returns queue statistics, including how many messages are in the queue, categorized by status.

@param [String] queue_name Specifies the name of the queue. @return [Excon::Response] response @raise [Fog::Rackspace::Queues::NotFound] - HTTP 404 @raise [Fog::Rackspace::Queues::BadRequest] - HTTP 400 @raise [Fog::Rackspace::Queues::InternalServerError] - HTTP 500 @raise [Fog::Rackspace::Queues::ServiceError] @see docs.rackspace.com/queues/api/v1.0/cq-devguide/content/GET_getQueueStats__version__queues__queue_name__stats_queue-operations-dle001.html

# File lib/fog/rackspace/requests/queues/get_queue_stats.rb, line 14
def get_queue_stats(queue_name)
  request(
    :expects => 200,
    :method => 'GET',
    :path => "queues/#{queue_name}/stats"
  )
end
list_messages(client_id, queue_name, options = {}) click to toggle source

This operation gets the message or messages in the specified queue.

A request to list messages when the queue is not found or when messages are not found returns 204, instead of 200, because there was no information to send back. Messages with malformed IDs or messages that are not found by ID are ignored.

@param [String] client_id UUID for the client instance. @param [String] queue_name Specifies the name of the queue. @param [Hash] options @option options [String] :marker - Specifies an opaque string that the client can use to request the next batch of messages. The marker parameter communicates to the

server which messages the client has already received. If you do not specify a value, the API returns all messages at the head of the queue (up to the limit).

@option options [Integer] :limit - When more messages are available than can be returned in a single request, the client can pick up the next batch of messages

by simply using the URI template parameters returned from the previous call in the "next" field. Specifies up to 10 messages (the default value) to return.
If you do not specify a value for the limit parameter, the default value of 10 is used.

@option options [String] :echo - Determines whether the API returns a client’s own messages. The echo parameter is a Boolean value (true or false) that determines

whether the API returns a client's own messages, as determined by the uuid portion of the User-Agent header. If you do not specify a value, echo uses the default
value of false. If you are experimenting with the API, you might want to set echo=true in order to see the messages that you posted.

@option options [String] :include_claimed - Determines whether the API returns claimed messages and unclaimed messages. The include_claimed parameter is a Boolean

value (true or false) that determines whether the API returns claimed messages and unclaimed messages. If you do not specify a value, include_claimed uses the
default value of false (only unclaimed messages are returned).

@return [Excon::Response] response @raise [Fog::Rackspace::Queues::NotFound] - HTTP 404 @raise [Fog::Rackspace::Queues::BadRequest] - HTTP 400 @raise [Fog::Rackspace::Queues::InternalServerError] - HTTP 500 @raise [Fog::Rackspace::Queues::ServiceError] @see docs.rackspace.com/queues/api/v1.0/cq-devguide/content/GET_getMessages__version__queues__queue_name__messages_message-operations-dle001.html

# File lib/fog/rackspace/requests/queues/list_messages.rb, line 30
def list_messages(client_id, queue_name, options = {})
  request(
    :expects => [200, 204],
    :method => 'GET',
    :path => "queues/#{queue_name}/messages",
    :headers => { 'Client-ID' => client_id },
    :query => options
  )
end
list_queues(options={}) click to toggle source

This operation lists queues for the project. The queues are sorted alphabetically by name. @note A request to list queues when you have no queues in your account returns 204, instead of 200, because there was no information to send back.

@param [Hash] options @option options [String] :marker - Specifies the name of the last queue received in a previous request, or none to get the first page of results. @option options [Integer] :limit - Specifies the name of the last queue received in a previous request, or none to get the first page of results. @option options [Boolean] :detailed - Determines whether queue metadata is included in the response. The default value for this parameter is false, which excludes t @return [Excon::Response] response @raise [Fog::Rackspace::Queues::NotFound] - HTTP 404 @raise [Fog::Rackspace::Queues::BadRequest] - HTTP 400 @raise [Fog::Rackspace::Queues::InternalServerError] - HTTP 500 @raise [Fog::Rackspace::Queues::ServiceError] @see docs.rackspace.com/queues/api/v1.0/cq-devguide/content/GET_listQueues__version__queues_.html

# File lib/fog/rackspace/requests/queues/list_queues.rb, line 18
def list_queues(options={})
  request(
    :expects => [200, 204],
    :method => 'GET',
    :path => 'queues',
    :query => options
  )
end
request(params, parse_json = true, &block) click to toggle source
Calls superclass method Fog::Rackspace::Service#request
# File lib/fog/rackspace/queues.rb, line 390
def request(params, parse_json = true, &block)
  super(params, parse_json, &block)
rescue Excon::Errors::NotFound => error
  raise NotFound.slurp(error, self)
rescue Excon::Errors::BadRequest => error
  raise BadRequest.slurp(error, self)
rescue Excon::Errors::InternalServerError => error
  raise InternalServerError.slurp(error, self)
rescue Excon::Errors::MethodNotAllowed => error
  raise MethodNotAllowed.slurp(error, self)
rescue Excon::Errors::HTTPStatusError => error
  raise ServiceError.slurp(error, self)
end
update_claim(queue_name, claim_id, ttl) click to toggle source

This operation posts the specified message or messages. @note You can submit up to 10 messages in a single request.

@param [String] queue_name Specifies the name of the queue. @param [Integer] ttl 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). @see docs.rackspace.com/queues/api/v1.0/cq-devguide/content/PATCH_updateClaim__version__queues_queue_name_claims__claimId__claims-operations-dle001.html

# File lib/fog/rackspace/requests/queues/update_claim.rb, line 11
def update_claim(queue_name, claim_id, ttl)
  body = {
    :ttl => ttl
  }
  request(
    :body => Fog::JSON.encode(body),
    :expects => 204,
    :method => 'PATCH',
    :path => "queues/#{queue_name}/claims/#{claim_id}"
  )
end