This repository is private.
All pages are served over SSL and all pushing and pulling is done over SSH.
No one may fork, clone, or view it unless they are added as a member.
Every repository with this icon (
) is private.
Every repository with this icon (
This repository is public.
Anyone may fork, clone, or view it.
Every repository with this icon (
) is public.
Every repository with this icon (
| name | age | message | |
|---|---|---|---|
| |
README.markdown | Thu Jan 22 07:37:41 -0800 2009 | |
| |
lib/ | Thu Jan 22 07:22:43 -0800 2009 | |
| |
retryable.gemspec | Thu Jan 22 07:22:43 -0800 2009 | |
| |
test/ | Sat Jan 10 08:38:20 -0800 2009 |
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.
require "retryable"
require "open-uri"
retryable( :tries => 3, :on => OpenURI::HTTPError ) do
xml = open( "http://example.com/test.xml" ).read
end
Do something, retry up to four times for either ArgumentError or
TimeoutError exceptions.
require "retryable"
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
Changelog
- v1.2: FIX -- block would run twice when
:trieswas set to0. (Thanks for the heads-up to Tuker.)
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! :)







