Just::Retry
A tiny gem that only provides a single retry method capable of catching specific exceptions, providing delays between retries and logging it's behavior.
Installation
Add this line to your application's Gemfile:
gem 'just-retry'
And then execute:
$ bundle
Or install it yourself as:
$ gem install just-retry
Then load it using:
require 'just/retry'
Examples
In it's most simple form it will retry the block one time on any exception with zero delay between attempts.
Just::retry do
# work
end
You can specify which exception is rescued.
Just::retry on: exception do
# work
end
You can specify the number of retry attempts
Just::retry tries: count do
# work
end
You can specify a delay that should occur before retries.
Just::retry delay: seconds do
# work
end
If you provide a logger it will record it's behavior. It will record any retry attempts at log level 'error' (recoverable errors) and provides additional information about the error rescued at log level 'debug'.
Just::retry logger: logger do
# work
end
An example that ties it all together.
Just::retry on: Timeout::Error, tries: 3, delay: 5, logger: Logger.new($stdout) do
# work
end
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request