Class: Fog::Rackspace::Queues::Real
- 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
-
#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.
-
#create_message(client_id, queue_name, body, ttl) ⇒ Excon::Response
This operation posts the specified message or messages.
-
#create_queue(queue_name) ⇒ Excon::Response
This operation creates a new queue.
-
#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.
-
#delete_message(queue_name, message_id, options = {}) ⇒ Excon::Response
This operation immediately deletes the specified message.
-
#delete_queue(queue_name) ⇒ Excon::Response
This operation immediately deletes a queue and all of its existing messages.
-
#get_claim(queue_name, claim_id) ⇒ Excon::Response
This operation queries the specified claim for the specified queue.
-
#get_message(client_id, queue_name, message_id) ⇒ Excon::Response
This operation gets the specified message from the specified queue.
-
#get_queue(queue_name) ⇒ Excon::Response
This operation verifies whether the specified queue exists.
-
#get_queue_stats(queue_name) ⇒ Excon::Response
This operation returns queue statistics, including how many messages are in the queue, categorized by status.
-
#initialize(options = {}) ⇒ Real
constructor
A new instance of Real.
-
#list_messages(client_id, queue_name, options = {}) ⇒ Excon::Response
This operation gets the message or messages in the specified queue.
-
#list_queues(options = {}) ⇒ Excon::Response
This operation lists queues for the project.
- #request(params, parse_json = true, &block) ⇒ Object
-
#update_claim(queue_name, claim_id, ttl) ⇒ Object
This operation posts the specified message or messages.
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.
381 382 383 384 385 386 387 388 |
# File 'lib/fog/rackspace/queues.rb', line 381 def initialize( = {}) () authenticate @persistent = [: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.
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, = {}) body = { :ttl => ttl, :grace => grace } query = {} query[:limit] = [:limit] if .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
You can submit up to 10 messages in a single request.
This operation posts the specified message or messages.
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 (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.
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.
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
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.
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/fog/rackspace/requests/queues/delete_message.rb', line 18 def (queue_name, , = {}) query = {} query[:claim_id] = [:claim_id] if .key? :claim_id request( :expects => 204, :method => 'DELETE', :path => "queues/#{queue_name}/messages/#{}", :query => query ) end |
#delete_queue(queue_name) ⇒ Excon::Response
This operation immediately deletes a queue and all of its existing messages.
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.
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.
16 17 18 19 20 21 22 23 |
# File 'lib/fog/rackspace/requests/queues/get_message.rb', line 16 def (client_id, queue_name, ) request( :expects => 200, :method => 'GET', :path => "queues/#{queue_name}/messages/#{}", :headers => { 'Client-ID' => client_id } ) end |
#get_queue(queue_name) ⇒ Excon::Response
This operation verifies whether the specified queue exists.
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.
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.
30 31 32 33 34 35 36 37 38 |
# File 'lib/fog/rackspace/requests/queues/list_messages.rb', line 30 def (client_id, queue_name, = {}) request( :expects => [200, 204], :method => 'GET', :path => "queues/#{queue_name}/messages", :headers => { 'Client-ID' => client_id }, :query => ) end |
#list_queues(options = {}) ⇒ Excon::Response
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.
18 19 20 21 22 23 24 25 |
# File 'lib/fog/rackspace/requests/queues/list_queues.rb', line 18 def list_queues(={}) request( :expects => [200, 204], :method => 'GET', :path => 'queues', :query => ) end |
#request(params, parse_json = true, &block) ⇒ Object
390 391 392 393 394 395 396 397 398 399 400 401 402 |
# 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) ⇒ Object
You can submit up to 10 messages in a single request.
This operation posts the specified message or messages.
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 |