Class: Fog::Rackspace::Queues::Real
- 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
- #authenticate(options = {}) ⇒ Object
- #client_id ⇒ Object
- #client_id=(client_id) ⇒ Object
-
#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.
- #endpoint_uri(service_endpoint_url = nil) ⇒ Object
-
#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.
- #region ⇒ Object
- #request(params, parse_json = true, &block) ⇒ Object
- #service_name ⇒ Object
-
#update_claim(queue_name, claim_id, ttl) ⇒ Object
This operation posts the specified message or messages.
Methods inherited from Service
#request_without_retry, #service_net?
Constructor Details
#initialize(options = {}) ⇒ Real
Returns a new instance of Real.
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/fog/rackspace/queues.rb', line 61 def initialize( = {}) @rackspace_api_key = [:rackspace_api_key] @rackspace_username = [:rackspace_username] @rackspace_queues_client_id = [:rackspace_queues_client_id] || Fog::UUID.uuid @rackspace_auth_url = [:rackspace_auth_url] @rackspace_must_reauthenticate = false @connection_options = [:connection_options] || {} @rackspace_region = [:rackspace_region] || :ord unless v2_authentication? raise Fog::Errors::NotImplemented.new("V2 authentication required for Queues") end authenticate @persistent = [:persistent] || false @connection = Fog::Connection.new(endpoint_uri.to_s, @persistent, @connection_options) end |
Instance Method Details
#authenticate(options = {}) ⇒ Object
98 99 100 101 102 103 104 105 |
# File 'lib/fog/rackspace/queues.rb', line 98 def authenticate(={}) super({ :rackspace_api_key => @rackspace_api_key, :rackspace_username => @rackspace_username, :rackspace_auth_url => @rackspace_auth_url, :connection_options => @connection_options }) end |
#client_id ⇒ Object
107 108 109 |
# File 'lib/fog/rackspace/queues.rb', line 107 def client_id @rackspace_queues_client_id end |
#client_id=(client_id) ⇒ Object
111 112 113 |
# File 'lib/fog/rackspace/queues.rb', line 111 def client_id=(client_id) @rackspace_queues_client_id = client_id end |
#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.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/fog/rackspace/requests/queues/create_claim.rb', line 20 def create_claim(queue_name, ttl, grace, = {}) body = { :ttl => ttl, :grace => grace } query = {} query[:limit] = [:limit] if .has_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.
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/fog/rackspace/requests/queues/create_message.rb', line 20 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.
16 17 18 19 20 21 22 23 |
# File 'lib/fog/rackspace/requests/queues/create_queue.rb', line 16 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.
17 18 19 20 21 22 23 |
# File 'lib/fog/rackspace/requests/queues/delete_claim.rb', line 17 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.
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/fog/rackspace/requests/queues/delete_message.rb', line 19 def (queue_name, , = {}) query = {} query[:claim_id] = [:claim_id] if .has_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.
15 16 17 18 19 20 21 |
# File 'lib/fog/rackspace/requests/queues/delete_queue.rb', line 15 def delete_queue(queue_name) request( :expects => 204, :method => 'DELETE', :path => "queues/#{queue_name}" ) end |
#endpoint_uri(service_endpoint_url = nil) ⇒ Object
94 95 96 |
# File 'lib/fog/rackspace/queues.rb', line 94 def endpoint_uri(service_endpoint_url=nil) @uri = super(@rackspace_endpoint || service_endpoint_url, :rackspace_queues_url) 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.
16 17 18 19 20 21 22 |
# File 'lib/fog/rackspace/requests/queues/get_claim.rb', line 16 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.
17 18 19 20 21 22 23 24 |
# File 'lib/fog/rackspace/requests/queues/get_message.rb', line 17 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.
15 16 17 18 19 20 21 |
# File 'lib/fog/rackspace/requests/queues/get_queue.rb', line 15 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.
15 16 17 18 19 20 21 |
# File 'lib/fog/rackspace/requests/queues/get_queue_stats.rb', line 15 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.
31 32 33 34 35 36 37 38 39 |
# File 'lib/fog/rackspace/requests/queues/list_messages.rb', line 31 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.
19 20 21 22 23 24 25 26 |
# File 'lib/fog/rackspace/requests/queues/list_queues.rb', line 19 def list_queues(={}) request( :expects => [200, 204], :method => 'GET', :path => 'queues', :query => ) end |
#region ⇒ Object
57 58 59 |
# File 'lib/fog/rackspace/queues.rb', line 57 def region @rackspace_region end |
#request(params, parse_json = true, &block) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/fog/rackspace/queues.rb', line 80 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 |
#service_name ⇒ Object
53 54 55 |
# File 'lib/fog/rackspace/queues.rb', line 53 def service_name :cloudQueues 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.
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/fog/rackspace/requests/queues/update_claim.rb', line 12 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 |