Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

41 lines (34 sloc) 0.839 kB
module Kernel
# FILE FROM PANDA VIDEO LIBRARY
# TO USE:
# begin
# retryable(:tries=>5) do
# .....
# end
# rescue
# ....
# end
# Options
# =======
# * :tries Number of retries to perform. Defaults to 1.
# Note this means it actually tries 2 times!
# * :on - The Exception on which a retry will be performed. Defaults to
# Exception, which retries on any Exception.
#
# Example
# =======
# retryable(:tries => 1, :on => OpenURI::HTTPError) do
# # your code here
# end
#
def retryable(options = {}, &block)
opts = { :tries => 1, :on => Exception }.merge(options)
retry_exception, retries = opts[:on], opts[:tries]
begin
return yield
rescue retry_exception
retry if (retries -= 1) > 0
end
yield
end
end
Jump to Line
Something went wrong with that request. Please try again.