2016-09-21 77 views
0

,所以我得到的连接失败,失败了,这说明这个错误:法拉第连接上rake任务

rake aborted! 

Faraday::ConnectionFailed: execution expired 

如何我能得到这个没有爆炸我的rake任务,只是无论是重试或跳到下一行?

我的继承人rake任务

require 'nokogiri' 
require 'open-uri' 
namespace :webtask do 
    task populate: :environment do 
    Event.all.each do |row| 
     tweventname = I18n.transliterate(row.eventname) 
     url = url here 
     doc = Nokogiri::HTML(open(url)) 
     doc.css('.table__row--event').each do |tablerow| 
     table = tablerow.css('.table__cell__body--location').css('h4').text 
     next unless table == row.eventvenuename 
      tablerow.css('.table__cell__body--availability').each do |button| 
      buttonurl = button.css('a')[0]['href'] 
      if buttonurl.include? '/checkout/external' 
       else 
      row.update(url: buttonurl) 
      end 
      end 
     end 
    end 
    end 
end 

回答

0

也许一个标准的救援块就是你需要的。

require 'nokogiri' 
require 'open-uri' 
namespace :webtask do 
    task populate: :environment do 
    Event.all.each do |row| 
     begin #Tells rescue where to jump 
     tweventname = I18n.transliterate(row.eventname) 
     url = url here 
     doc = Nokogiri::HTML(open(url)) 
     doc.css('.table__row--event').each do |tablerow| 
     table = tablerow.css('.table__cell__body--location').css('h4').text 
     next unless table == row.eventvenuename 
      tablerow.css('.table__cell__body--availability').each do |button| 
      buttonurl = button.css('a')[0]['href'] 
      if buttonurl.include? '/checkout/external' 
       else 
      row.update(url: buttonurl) 
      end 
      end 
     end 
    end 
    rescue Faraday::ConnectionFailed 
    next 
    end 
    end 
end 
+0

嘿,那里,谢谢你的答案,但我得到了一个错误,这很糟糕! –