Julien Biard
2007-Jul-20 12:35 UTC
[Backgroundrb-devel] Backgroundrb and timeout connections
Hi We have a RoR application which needs to get the contents of RSS feeds. The application opens HTTP connections, but the problem is that we have frequently Timeout::Error because of feeds are not available. It seems it''not possible to reduce the time of timeout in Ruby... So, I''m wondering if there is way to solve this with Backgroundrb. Best regards, Julien
On 7/20/07, Julien Biard <julien.biard at citycampus.com> wrote:> Hi > > We have a RoR application which needs to get the contents of RSS feeds. > The application opens HTTP connections, but the problem is that we have > frequently Timeout::Error because of feeds are not available. It seems > it''not possible to reduce the time of timeout in Ruby... So, I''m > wondering if there is way to solve this with Backgroundrb. > > Best regards,I am afraid BackgrounDRb can''t help you there, but you can handle timeout errors like this. class FeedWorker def do_work yahoo_url = "http://finance.yahoo.com/rss/headline?s=" symbol_list = [''IBM'',''GOOG'',''FUCK''] symbol_list.each do|sym| temp_url = yahoo_url + sym begin get_feeds(temp_url,sym) rescue Timeout::Error next rescue puts $! puts $!.backtrace next end end end def get_feeds(url,temp_sym) open(url) do |http| t_response = http.read puts t_response end end end If you really want to reduce timeout period for attempting fetch of a page, then you call the method get_feeds in a block like this: begin timeout(3) do get_feeds(temp_url,sym) end rescue Timeout::Error end I hope this solves your problem. -- Let them talk of their oriental summer climes of everlasting conservatories; give me the privilege of making my own summer with my own coals. http://blog.gnufied.org