Skip to content

Commit

Permalink
retry
Browse files Browse the repository at this point in the history
  • Loading branch information
sorah committed Oct 31, 2015
1 parent af22acf commit 39c1a73
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions 5f/webapp/ruby/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,24 @@ def fetch_http(headers, params, call_uri, conf)
raise "unknown method #{method}"
end

s = Time.now
res = @client.request(call_uri, req)
e = Time.now
retried = false


begin
s = Time.now
res = @client.request(call_uri, req)
e = Time.now

res.value
rescue Exception => err
e ||= Time.now
s ||= Time.now
if res && res.code == '429' && !retried
retried = true
$stderr.puts "[API CALL][HTTP][RETRY] #{method} #{call_uri} (#{"%.2f" % (e-s)}s, #{err.inspect}) #{headers.inspect}"
retry
sleep 1
end
$stderr.puts "[API CALL][HTTP][ERROR] #{method} #{call_uri} (#{"%.2f" % (e-s)}s, #{err.inspect}) #{headers.inspect}"
raise
end
Expand Down

0 comments on commit 39c1a73

Please sign in to comment.