<commit_before># 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 "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.

    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](http://gems.github.com/). Then, install the gem:

    sudo gem install carlo-retryable
    

## Todo

* Unit tests


## Changelog

*   1.2: FIX -- block would run twice when `:tries` was set to `0`. (Thanks for the
    heads-up to [Tuker](http://github.com/tuker).)


## Thanks

Many thanks to [Ch<NAME> for this nifty piece of code](http://blog.codefront.net/2008/01/14/retrying-code-blocks-in-ruby-on-exceptions-whatever/). Look, I liked it
enough to enhance it a little bit and build a gem from it! :)

<commit_msg>Markup upfuckery.<commit_after># 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 "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.

    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](http://gems.github.com/). Then, install the gem:

    sudo gem install carlo-retryable
    

## Todo

* Unit tests


## Changelog

*   v1.2: FIX -- block would run twice when `:tries` was set to `0`. (Thanks for the
    heads-up to [Tuker](http://github.com/tuker).)


## Thanks

Many thanks to [<NAME> for this nifty piece of code](http://blog.codefront.net/2008/01/14/retrying-code-blocks-in-ruby-on-exceptions-whatever/). Look, I liked it
enough to enhance it a little bit and build a gem from it! :)


{'fraction_non_alphanumeric': 0.11519198664440734, 'fraction_numerical': 0.01001669449081803, 'mean_word_length': 3.2861230329041486, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2680582', 'n_tokens_mistral': 994, 'n_tokens_neox': 955, 'n_words': 367}