##New in version 2.0.0## This version is incompatible with ruby < 2.x Also, if kill == true, it preserves the original error to show you what really went wrong ##### This method is usefull for when you want to attempt to get a resource on a network and it may fail. Or maybe you know that there's a possibility that the databases haven't sync yet and you want to try a few times till they do. This is one of the first few pieces of code I ever wrote in Ruby, it was intented to be help on random failure we had on automated testes where we were testing big applications that included many machines and databases whose sync was not always perfect (or our tests were too fast for the sync). It's really easy to use Just do require 'try_again' TryAgain.retry do some code end By default it attempts your code 3 times with a 3 seconds sleep in between IF your code raises a StandardError. I SERIOUSLY recomend your code to raise some other error other than StandardError, or you may have some unexpected results when something that shouldn't fail does. You have a few options that you can pass: :attempts => (int) number of times to try run block till give up; defaults 3 :sleep => (int) seconds between each attempt; defaults 3 :error => (Constant) error to listen to; defaults StandardError :output => Debug mode, but you can send anything that responds to :puts and you'll get debug info there; defaults nil :kill => (Boolean) If true after the last attempt it will raise your error back to you; defaults false You pass them as an hash like so: TryAgain.retry(:error => MyCustomErrorClass) do raise MyCustomErrorClass if something end Finally, if :kill => false TryAgain.retry returns a Boolean telling you whatever there was an error or not.
Project
try_again
This method is usefull for when you want to attempt to get a resource on a network and it may fail
Or maybe you know that there's a possibility that the databases haven't sync yet and you want to try a few times till they do
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
Development
Dependencies
Project Readme