Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Kernel#retryable, by Cheah Chu Yeow (http://is.gd/faW9), slightly enhanced and rebuilt as gem as a little Munich Hackday project.
Ruby
tree: 049df80827

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
test
README
README.markdown
retryable.gemspec

README.markdown

Kernel#retryable

Description

Runs a code block, and retries it when an exception occurs. It's great when working with flakey webservices (for example).

It's configured using two optional parameters --:tries and :on--, and runs the passed block. Should an exception occur, it'll retry for (n-1) times.

Should the number of retries be reached without success, the last exception will be raised.

Examples

Open an URL, retry up to two times when an OpenURI::HTTPError occurs.

retryable( :tries => 3, :on => OpenURI:HTTPError ) do
  xml = open( xml_url ).read
end

Do something, retry up to four times for either ArgumentError or TimeoutError exceptions.

retryable( :tries => 5, :on => [ ArgumentError, TimeoutError ] ) do
  # some crazy code
end

Defaults

:tries => 1, :on => Exception

Installation

First, make sure GitHub is a gem source. Then, install the gem:

sudo gem install carlo-retryable

Todo

  • Unit tests

Thanks

Many thanks to Chu Yeow for this nifty piece of code. Look, I liked it enough to enhance it a little bit and build a gem from it! :)

Something went wrong with that request. Please try again.