def with_retry(retry_limit=3)
exception = nil
retry_limit.times do |i|
begin
return yield()
rescue Exception => ex
print "Attempt #{i + 1} of #{retry_limit} failed: #{ex}\n"
exception = ex
end
end
raise exception
end
def some_function()
return 'baz'
end
counter = 0
result = with_retry do
counter += 1
print "body #{counter}\n"
if counter < 4
raise Exception.new('bad')
end
some_function()
end
print "result: #{result}"
Created
September 2, 2013 06:52
-
-
Save liyanage/6409883 to your computer and use it in GitHub Desktop.
Ruby cheat sheet
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment