From: Dan Date: 2010-02-23T03:53:09+09:00 Subject: Ruby Idiom To Retry open() Upto N Times Before Giving Up --0-241528343-1266864387=:62966 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable I write a lot of scripts that I run once or infrequently that uses open-rui= . Occasionally I run into a web site that times out or is unavailable for a= period of time. My normal solution is to just rerun the script manually at= a later time and the problem goes away. What I would like to start doing i= s rescuing the open() and retrying the open() after a delay. What would be = the most idiomatic way to try opening a url say n times before giving up? H= ere is my crude code for trying twice: begin=A0=20 =A0=A0 open("http://www.example.com/foo.html") =A0rescue=A0=20 =A0=A0 begin=A0=20 =A0=A0=A0=A0=A0 open("http://www.example.com/foo.html") =A0=A0=A0 rescue=A0=20 =A0=A0=A0=A0=A0 #tried twice - giving up=A0=20 =A0=A0 end=A0=20 end=A0=20 I would like a more general approach using ruby idioms where I could specif= y the maximum number of attempts and delay before giving up. Thanks for you= r help. --0-241528343-1266864387=:62966--