Skip to content

Instantly share code, notes, and snippets.

@leosoto
Created July 9, 2010 18:41
Show Gist options
  • Save leosoto/469846 to your computer and use it in GitHub Desktop.
Save leosoto/469846 to your computer and use it in GitHub Desktop.
def retrying(attempts, options = {})
exception_class = options[:when] || Exception
sleep_time = options[:sleep] || 0.seconds
last_exception = nil
attempts.each do
begin
return yield
rescue exception_class => last_exception
Kernel.sleep sleep_time.to_f
end
end
raise last_exception
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment