[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

How to retry a disrupted Net::HTTP download?

Chris Colon

6/4/2007 11:37:00 AM

Hi,
I'm trying to download a file with Ruby from a website. Everything works
fine, but I can't get Ruby to retry the download when for example the
internet connection breaks during the download.

Here's my code so far (it's easier to read in a pastie):
http://pastie.cabo...

The Timeout::Error exception never happens, even though it should time
out after 5 seconds. The funny thing is, if I deactivate my internet and
then reconnect it, it does continue the download of the file, even
though the commands under "rescue Timeout::Error" aren't executed.

I hope someone can help me, I googled for an hour and tried tons of
different things that I found in the API docs, but I'm pretty stuck
right now.

--
Posted via http://www.ruby-....

1 Answer

Chris Colon

6/5/2007 9:40:00 AM

0

Okay I found it out by myself, here's the working code if someone else
ever wants to do this:
http://pastie.cabo...

The problem was that Ruby already uses a timeout for the Net::HTTP class
and because of this, you can't wrap another timeout around it. But you
can set the timeout Ruby uses with http.read_timeout and
http.open_timeout. This way I was able to handle the Timeout::Error and
now everything works just fine.

Chris Colon wrote:
> Hi,
> I'm trying to download a file with Ruby from a website. Everything works
> fine, but I can't get Ruby to retry the download when for example the
> internet connection breaks during the download.
>
> Here's my code so far (it's easier to read in a pastie):
> http://pastie.cabo...
>
> The Timeout::Error exception never happens, even though it should time
> out after 5 seconds. The funny thing is, if I deactivate my internet and
> then reconnect it, it does continue the download of the file, even
> though the commands under "rescue Timeout::Error" aren't executed.
>
> I hope someone can help me, I googled for an hour and tried tons of
> different things that I found in the API docs, but I'm pretty stuck
> right now.


--
Posted via http://www.ruby-....