Skip to content

Instantly share code, notes, and snippets.

@wtnabe
Created March 5, 2009 05:39
Show Gist options
  • Save wtnabe/74214 to your computer and use it in GitHub Desktop.
Save wtnabe/74214 to your computer and use it in GitHub Desktop.
A retrier for poor quality network and servers
#
# always retry
#
# ex)
# do_with_retry( 'dns' ) { Resolv.getaddress( 'example.com' ) }
#
def do_with_retry( name, &block )
times = RETRY_LIMIT
begin
block.call
rescue => e
if ( times > 0 )
times -= 1
sleep( rand( 3 ) )
@logger.info( "retry #{name}" ) if ( @logger )
retry
else
raise e
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment