Skip to content

Instantly share code, notes, and snippets.

@technicalpickles
Created November 11, 2014 19:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save technicalpickles/a4581caa9378549dd59d to your computer and use it in GitHub Desktop.
Save technicalpickles/a4581caa9378549dd59d to your computer and use it in GitHub Desktop.
ruby retry example-
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