Re-reading FTP and HTTP URI with Typhoeus?

Having discussed some of the errors in " Is Ruby" open_uri "really reliably closing sockets after reading or on failure? I wanted to delve into this a little deeper.

I would like to try to pull the data from the FTP server, and then if that fails, try to pull the data from the HTTP server. If both of them fail, I would like to cycle around and retry several times with a short pause between attempts (maybe 1 second)

I read about the "retryable" method in " Re-blocking blocks of code in Ruby (exceptions, anything) , however retryable-rb can be more reliable.

I would need to see an example from the old hat on this scenario, because I need a reliable mechanism to extract data from several semi-reliable sources that I have. As noted in another thread, it seems that Typhoeus can offer a reliable component for this solution.

0
source share
1 answer

Using one of these gemstones might be a good idea, but it's pretty simple without them:

data = nil
until data
# or 5.times do
    data = open(ftp_url){|f| f.read} rescue nil
    data ||= open(http_url){|f| f.read} rescue nil
    break if data
    sleep 1
end
+1
source

All Articles