2014-09-02 33 views
0

我用Feedjira解析RSS流。 當我使用fetch_and_parse方法時,它有時會被阻塞並且不會響應。路邊沒有迴應

同樣的事情發生在手動遏制下載。

我寫在一個循環:

@my_logger.info "--- Before perform ---" 
easy = Curl::Easy.new 
easy.follow_location = true 
easy.max_redirects = 3 
easy.connect_timeout = 120 
easy.url = url 
easy.useragent = "Ruby/Curb" 
easy.perform 
@my_logger.info "--- After perform ---" 
doc = easy.body_str 
easy.close 

一段時間之後(也可能是一天或一小時),過程停止在easy.perform線和不響應。例如。過程輸出--- Before perform ---,沒有別的。

回答

1

它可能與隨機發生的網絡問題有關。

如果您使用超時,則可以在長時間運行的任務中跳過這種情況。

require 'timeout' 
begin 
    Timeout.timeout(5) do  
    easy.perform 
    end 
rescue Timeout::Error 
    puts 'timeout' 
end