WindowsAzure/azure-sdk-for-ruby — pull request #71 by Blackmist (2013-05-28 17:24:31+00:00)
Title: Fixing retry

Fixing the retry_policy. Previously, it wouldn't load as the require statement had a leading slash. It also tried calling should_retry? which was defined as should_try? so that wouldn't work. Also, any HTTP response other than 200 would raise an exception that would prevent the retry_policy from operating. So I added a rescue that saves the exception so it can be used/evaluated by retry logic.

To use, do something like:

require "azure"
require "azure/core/http/debug_filter"
require "azure/core/http/retry_policy"
retry_thing = Azure::Core::Http::RetryPolicy.new { |response, data|
return false unless data.has_key?(:error)
if data.has_key?(:count) then
data[:count] += 1
return false if data[:count] > 3
else
data[:count] = 0
end
puts "current count #{data[:count]}"
return true
}

This checks to see if an error was captured, and if so initializes a retry count, then increments each retry attempt, finally returning false when count > 3.