我有一个rake任务,使用回形针从表网站加载汽车的图像。图像作为远程链接存储在数据库中。Rails Rake任务显示执行过期消息和程序停止
这里是我的代码,我使用红宝石1.8.7,导轨2.3.8和DB mysql。
namespace :db do
task :load_photo => :environment do
require 'rubygems'
require 'open-uri'
require 'net/http'
require 'paperclip'
begin
images =Website.find(:all,:conditions=>["image_url is not null"])
images.each do |photo|
url = URI.parse(photo.image_url)
Net::HTTP.start(url.host, url.port) do |http|
if http.head(url.request_uri).code == "200"
Car.update_attribute(:photo,open(url))
end
end
end
rescue Exception => e
end
end
end
通过db:load_photo运行在rake任务之上。在我的表(网站)有60,000行。 Rake任务最多只能运行10000行,并且执行以错误消息“execution expired”终止。
任何人都可以帮我解决这个问题吗?
在此先感谢。
尝试用'read_timeout' http://ruby-doc.org/stdlib/libdoc/net/http/rdoc/classes/Net/HTTP.html玩#M001372 – 2011-06-10 10:33:34
你可以显示rake db的输出:load_photo --trace – 2011-06-10 12:14:54