Permalink
Browse files

Backoff seems to be just fine.

  • Loading branch information...
1 parent a5d928e commit 25697a0c6285aed40d28d533731e30c809f61830 @treeder treeder committed Jul 9, 2012
Showing with 28 additions and 7 deletions.
  1. +4 −4 Gemfile.lock
  2. +4 −2 lib/rest/client.rb
  3. +1 −1 test/test_base.rb
  4. +5 −0 test/test_rest.rb
  5. +14 −0 test/tmp.rb
View
@@ -1,20 +1,21 @@
PATH
remote: .
specs:
- rest (1.1.0)
+ rest (1.2.1)
+ net-http-persistent
rest-client (>= 0.3.0)
GEM
remote: https://rubygems.org/
specs:
ffi (1.0.11)
- mime-types (1.18)
+ mime-types (1.19)
net-http-persistent (2.7)
quicky (0.0.1)
rake (0.9.2.2)
rest-client (1.6.7)
mime-types (>= 1.16)
- test-unit (2.5.0)
+ test-unit (2.5.1)
typhoeus (0.4.2)
ffi (~> 1.0)
mime-types (~> 1.18)
@@ -24,7 +25,6 @@ PLATFORMS
ruby
DEPENDENCIES
- net-http-persistent
quicky
rake
rest!
View
@@ -82,6 +82,8 @@ def get(url, req_hash={})
return res
end
+ # This will attempt to perform the operation with an exponential backoff on 503 errors.
+ # Amazon services throw 503
def perform_op(&blk)
max_retries = @options[:max_retries] || 5
current_retry = 0
@@ -97,9 +99,9 @@ def perform_op(&blk)
s = Random.rand * pow
#puts 's=' + s.to_s
sleep_secs = 1.0 * s / 1000.0
- #puts 'sleep for ' + sleep_secs.to_s
+ puts 'sleep for ' + sleep_secs.to_s
current_retry += 1
- @logger.debug "503 Error. Retrying #{current_retry} out of #{max_retries} max."
+ @logger.debug "503 Received. Retrying #{current_retry} out of #{max_retries} max in #{sleep_secs} seconds."
sleep sleep_secs
else
break
View
@@ -14,7 +14,7 @@ def setup
puts 'setup'
#@config = YAML::load_file(File.expand_path(File.join("~", "Dropbox", "configs", "rest", "test", "config.yml")))
@rest = Rest::Client.new
- #@client.logger.level = Logger::DEBUG
+ @rest.logger.level = Logger::DEBUG
end
end
View
@@ -19,7 +19,12 @@ def test_basics
assert response.code == 200
#p response.body
assert response.body.include?("Social Coding")
+ end
+ def test_backoff
+ response = @rest.get("http://smooth-sword-1395.herokuapp.com/code/503?switch_after=3&switch_to=200")
+ p response
+ p response.code
end
def test_gets
View
@@ -0,0 +1,14 @@
+require 'yaml'
+begin
+ require File.join(File.dirname(__FILE__), '../lib/rest')
+rescue Exception => ex
+ puts "Could NOT load gem: " + ex.message
+ raise ex
+end
+
+@rest = Rest::Client.new # (:gem=>:rest_client)
+@rest.logger.level = Logger::DEBUG
+
+response = @rest.get("http://smooth-sword-1395.herokuapp.com/code/503?switch_after=3&switch_to=200")
+p response
+p response.code

0 comments on commit 25697a0

Please sign in to comment.