Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jameswhite/c5b53de6831778ce5ccb to your computer and use it in GitHub Desktop.
Save jameswhite/c5b53de6831778ce5ccb to your computer and use it in GitHub Desktop.
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