From: Daniel Berger Date: 2006-06-10T00:54:50+09:00 Subject: Re: Package idea: attempt ara.t.howard@noaa.gov wrote: > On Fri, 9 Jun 2006, Daniel Berger wrote: > >> Yep, definitely something to watch out for. What can I say? Use with >> caution. :) > > for what it's worth have my own version of attempt in a few near-real-time > systems where the overriding principle is : keep going at all costs. in > these > systems the 'fail big and fail early' priciple doesn't work unless one > enjoys > working on sundays - so i've got lots of stuff like attempt - it all > logs to > stderr and/or logs however, so it doesn't go unnoticed. > > on another note i've found that incremental sleep increse with reset is > almost > always what you want. retrying on the same interval seems to clog up > systems > as you get in certain timing rythyms. in rq i use this alot > > http://codeforpeople.com/lib/ruby/rq/rq-2.3.3/lib/rq-2.3.3/sleepcycle.rb > > it's a cycle that looks like a sawtooth wave - so basically on each > retry we > timeout for longer than before, essentially becoming more and more > 'patient' > before getting really 'impatient' again. > > i've found this matched the real world pretty well since timing out a > bunch in > a short period normally means you should wait longer. > > cheers. > > -a Hm, interesting. Maybe a more advanced version would use a full fledged class with lots of options. Something like this: attempt = Attempt.new{ |a| a.tries = 3 # Try 3 times a.interval = 30 # 30 seconds between tries but... a.max = 90 # In case of nested retries a.increment = 10 # add 10 seconds to the interval with each try a.log = log # Where 'log' is an IO handle a.warnings = $stderr # Send caught errors to IO handle as warnings } attempt{ # Some op } Attempt#max would, in theory, be used to prevent Jim Weirich's nightmare scenario, where you have a bunch of nested retries, all doing their own sleep + retry thing. So, using the above example, if I did something like this: attempt{ begin # some op rescue sleep 500 retry end } It would error out at 90 seconds no matter what (the value we set to 'max'). I'm not sure if that's possible, however, or even how you would implement it. Thoughts? - Dan