Forked from technicalpickles/gist:a4581caa9378549dd59d
Last active
August 29, 2015 14:09
-
-
Save jameswhite/c5b53de6831778ce5ccb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def flaky_code() | |
unless @flaky_code_works | |
@flaky_code_works = true | |
raise 'wtf' | |
end | |
puts "works eventually lol" | |
end | |
max_attempts = 5 | |
attempt = 1 | |
begin | |
flaky_code() | |
rescue => e | |
if attempt <= max_attempts | |
sleep 1 * attempt | |
attempt += 1 | |
puts "rety attempt #{attempt}" | |
retry | |
else | |
raise e | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment