Skip to content

Commit

Permalink
Merge pull request #28 from masahiro-nakajima/add-retry-to-request
Browse files Browse the repository at this point in the history
Add 'retry_count' of request to core_service options.
  • Loading branch information
johnny.halife committed Mar 7, 2013
2 parents c737d9e + 816987b commit 8b07b90
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
waz-storage (1.2.0)
waz-storage (1.3.0)
rest-client
ruby-hmac

Expand Down
16 changes: 14 additions & 2 deletions lib/waz/storage/core_service.rb
Expand Up @@ -4,6 +4,7 @@ module Storage
# this module is imported from WAZ::Queues::Service and WAZ::Blobs::Service.
module SharedKeyCoreService
attr_accessor :account_name, :access_key, :use_ssl, :base_url, :type_of_service, :use_devenv, :use_sas_auth_only, :sharedaccesssignature
attr_accessor :retry_count

# Creates an instance of the implementor service (internally used by the API).
def initialize(options = {})
Expand All @@ -17,7 +18,8 @@ def initialize(options = {})
self.use_ssl = options[:use_ssl] or false
self.use_devenv = !!options[:use_devenv]
self.base_url = "#{options[:type_of_service] or "blobs"}.#{options[:base_url] or "core.windows.net"}" unless self.use_devenv
self.base_url ||= (options[:base_url] or "core.windows.net")
self.base_url ||= (options[:base_url] or "core.windows.net")
self.retry_count = (options[:retry_count] or 5)
end

# Generates a request based on Adam Wiggings' rest-client, including all the required headers
Expand Down Expand Up @@ -116,7 +118,17 @@ def execute(verb, path, query = {}, headers = {}, payload = nil)
escaped_path = path.split("/").map{ | part | CGI.escape(part) }.join("/")
url = generate_request_uri(escaped_path, query)
request = generate_request(verb, url, headers, payload)
request.execute()

errors = 0
begin
request.execute()
rescue Errno::ETIMEDOUT, Errno::ECONNREFUSED, Errno::ECONNRESET => e
errors += 1
if errors > self.retry_count
raise e.class, e.message, e.backtrace
end
retry
end
end
end
end
Expand Down

0 comments on commit 8b07b90

Please sign in to comment.