Class: Fog::Rackspace::Queues::Real

Inherits:
Service
  • Object
show all
Includes:
Common
Defined in:
lib/fog/rackspace/queues.rb,
lib/fog/rackspace/requests/queues/get_claim.rb,
lib/fog/rackspace/requests/queues/get_queue.rb,
lib/fog/rackspace/requests/queues/get_message.rb,
lib/fog/rackspace/requests/queues/list_queues.rb,
lib/fog/rackspace/requests/queues/create_claim.rb,
lib/fog/rackspace/requests/queues/create_queue.rb,
lib/fog/rackspace/requests/queues/delete_claim.rb,
lib/fog/rackspace/requests/queues/delete_queue.rb,
lib/fog/rackspace/requests/queues/update_claim.rb,
lib/fog/rackspace/requests/queues/list_messages.rb,
lib/fog/rackspace/requests/queues/create_message.rb,
lib/fog/rackspace/requests/queues/delete_message.rb,
lib/fog/rackspace/requests/queues/get_queue_stats.rb

Instance Method Summary collapse

Methods included from Common

#apply_options, #authenticate, #client_id, #client_id=, #endpoint_uri, #region, #service_name

Methods inherited from Service

#authenticate, #endpoint_uri, #region, #request_without_retry, #service_name, #service_net?

Constructor Details

#initialize(options = {}) ⇒ Real

Returns a new instance of Real.



374
375
376
377
378
379
380
381
# File 'lib/fog/rackspace/queues.rb', line 374

def initialize(options = {})
  apply_options(options)

  authenticate

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

Instance Method Details

#create_claim(queue_name, ttl, grace, options = {}) ⇒ Excon::Response

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.

Parameters:

  • queue_name (String)

    Specifies the name of the queue.

  • ttl (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).

  • grace (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).

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :limit (Integer)
    • Specifies the number of messages to return, up to 20 messages. If limit is not specified, limit defaults to 10.

Returns:

  • (Excon::Response)

    response

Raises:

See Also:



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# 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) ⇒ Excon::Response

Note:

You can submit up to 10 messages in a single request.

This operation posts the specified message or messages.

Parameters:

  • client_id (String)

    UUID for the client instance.

  • queue_name (String)

    Specifies the name of the queue.

  • body (String, Hash, Array)

    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.

  • ttl (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).

Returns:

  • (Excon::Response)

    response

Raises:

See Also:



19
20
21
22
23
24
25
26
27
28
29
30
31
# 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) ⇒ Excon::Response

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

Parameters:

  • queue_name (String)

    Specifies the name of the queue.

Returns:

  • (Excon::Response)

    response

Raises:

See Also:



15
16
17
18
19
20
21
22
# 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) ⇒ Excon::Response

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.

Parameters:

  • queue_name (String)

    Specifies the name of the queue.

  • claim_id (String)

    Specifies the claim ID.

Returns:

  • (Excon::Response)

    response

Raises:

See Also:



16
17
18
19
20
21
22
# 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 = {}) ⇒ Excon::Response

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.

This operation immediately deletes the specified message.

Parameters:

  • queue_name (String)

    Specifies the name of the queue.

  • message_id (String)

    Specifies the message ID.

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :claim_id (Integer)
    • Identifies the claim.

Returns:

  • (Excon::Response)

    response

Raises:

See Also:



18
19
20
21
22
23
24
25
26
27
# 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) ⇒ Excon::Response

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

Parameters:

  • queue_name (String)

    Specifies the name of the queue.

Returns:

  • (Excon::Response)

    response

Raises:

See Also:



14
15
16
17
18
19
20
# 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) ⇒ Excon::Response

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

Parameters:

  • queue_name (String)

    Specifies the name of the queue.

  • claim_id (Integer)

    Specifies the claim ID.

Returns:

  • (Excon::Response)

    response

Raises:

See Also:



15
16
17
18
19
20
21
# 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) ⇒ Excon::Response

This operation gets the specified message from the specified queue.

Parameters:

  • client_id (String)

    UUID for the client instance.

  • queue_name (String)

    Specifies the name of the queue.

  • message_id (Integer)

    Specifies the message ID.

Returns:

  • (Excon::Response)

    response

Raises:

See Also:



16
17
18
19
20
21
22
23
# 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) ⇒ Excon::Response

This operation verifies whether the specified queue exists.

Parameters:

  • queue_name (String)

    Specifies the name of the queue.

Returns:

  • (Excon::Response)

    response

Raises:

See Also:



14
15
16
17
18
19
20
# 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) ⇒ Excon::Response

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

Parameters:

  • queue_name (String)

    Specifies the name of the queue.

Returns:

  • (Excon::Response)

    response

Raises:

See Also:



14
15
16
17
18
19
20
# 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 = {}) ⇒ Excon::Response

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.

Parameters:

  • client_id (String)

    UUID for the client instance.

  • queue_name (String)

    Specifies the name of the queue.

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :marker (String)
    • 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).

  • :limit (Integer)
    • 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.

  • :echo (String)
    • 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.

  • :include_claimed (String)
    • 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).

Returns:

  • (Excon::Response)

    response

Raises:

See Also:



30
31
32
33
34
35
36
37
38
# 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 = {}) ⇒ Excon::Response

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.

This operation lists queues for the project. The queues are sorted alphabetically by name.

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :marker (String)
    • Specifies the name of the last queue received in a previous request, or none to get the first page of results.

  • :limit (Integer)
    • Specifies the name of the last queue received in a previous request, or none to get the first page of results.

  • :detailed (Boolean)
    • Determines whether queue metadata is included in the response. The default value for this parameter is false, which excludes t

Returns:

  • (Excon::Response)

    response

Raises:

See Also:



18
19
20
21
22
23
24
25
# 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) ⇒ Object



383
384
385
386
387
388
389
390
391
392
393
394
395
# File 'lib/fog/rackspace/queues.rb', line 383

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) ⇒ Object

Note:

You can submit up to 10 messages in a single request.

This operation posts the specified message or messages.

Parameters:

  • queue_name (String)

    Specifies the name of the queue.

  • ttl (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).

See Also:



11
12
13
14
15
16
17
18
19
20
21
# 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