所以我得到连接失败,这显示了这个错误:
rake aborted!
Faraday::ConnectionFailed: execution expired
我怎样才能避免我的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 :(得分: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