Ruby on rails 延迟作业排队方法的新错误
这是我的模型:Ruby on rails 延迟作业排队方法的新错误,ruby-on-rails,delayed-job,Ruby On Rails,Delayed Job,这是我的模型: class Scraper def perform Tracker.all.each do |tracker| doc = Nokogiri::XML(open('http://share.findmespot.com/messageService/guestlinkservlet?glId=' + tracker.glid + '&completeXml=true') ) doc.xpath('//messageList/message').ma
class Scraper
def perform
Tracker.all.each do |tracker|
doc = Nokogiri::XML(open('http://share.findmespot.com/messageService/guestlinkservlet?glId=' + tracker.glid + '&completeXml=true') )
doc.xpath('//messageList/message').map do |m|
s = Spot.new({ :tracker_id => Tracker.find_by_esn(m.xpath('esn').text).id, :messagetype => m.xpath('messageType').text, :timestamp => m.xpath('timestamp').text, :latitude => m.xpath('latitude').text, :longitude => m.xpath('longitude').text, :timeingmtsecond => m.xpath('timeingmtsecond').text})
s.save
end
end
Delayed::Job.enqueue(Scraper.new, :run_at => 5.minutes.from_now)
end
def error(job, exception)
# Send a warning email to yourself, or whatever.
# The scraping will automatically be retried.
end
def success(job)
# Schedule the next scraping.
end
结束
获取此错误:
> ** Execute gps_start rake aborted! undefined method `to_i' for {:run_at=>Fri, 21 Oct 2011 11:37:19 EDT -04:00}:Hash
> /app/.bundle/gems/ruby/1.8/gems/delayed_job-2.0.7/lib/delayed/backend/base.rb:21:in
> `enqueue' /app/lib/scraper.rb:16:in `perform'
> /app/lib/tasks/tracker.rake:4
> /app/.bundle/gems/ruby/1.8/gems/rake-0.9.2/lib/rake/task.rb:205:in
> `call'
> /app/.bundle/gems/ruby/1.8/gems/rake-0.9.2/lib/rake/task.rb:205:in
> `execute'
> /app/.bundle/gems/ruby/1.8/gems/rake-0.9.2/lib/rake/task.rb:200:in
> `each'
> /app/.bundle/gems/ruby/1.8/gems/rake-0.9.2/lib/rake/task.rb:200:in
> `execute'
> /app/.bundle/gems/ruby/1.8/gems/rake-0.9.2/lib/rake/task.rb:158:in
> `invoke_with_call_chain' /usr/ruby1.8.7/lib/ruby/1.8/monitor.rb:242:in
> `synchronize'
> /app/.bundle/gems/ruby/1.8/gems/rake-0.9.2/lib/rake/task.rb:151:in
> `invoke_with_call_chain'
> /app/.bundle/gems/ruby/1.8/gems/rake-0.9.2/lib/rake/task.rb:144:in
> `invoke'
> /app/.bundle/gems/ruby/1.8/gems/rake-0.9.2/lib/rake/application.rb:112:in
> `invoke_task'
> /app/.bundle/gems/ruby/1.8/gems/rake-0.9.2/lib/rake/application.rb:90:in
> `top_level'
> /app/.bundle/gems/ruby/1.8/gems/rake-0.9.2/lib/rake/application.rb:90:in
> `each'
> /app/.bundle/gems/ruby/1.8/gems/rake-0.9.2/lib/rake/application.rb:90:in
> `top_level'
> /app/.bundle/gems/ruby/1.8/gems/rake-0.9.2/lib/rake/application.rb:129:in
> `standard_exception_handli ng'
> /app/.bundle/gems/ruby/1.8/gems/rake-0.9.2/lib/rake/application.rb:84:in
> `top_level'
> /app/.bundle/gems/ruby/1.8/gems/rake-0.9.2/lib/rake/application.rb:62:in
> `run'
> /app/.bundle/gems/ruby/1.8/gems/rake-0.9.2/lib/rake/application.rb:129:in
> `standard_exception_handli ng'
> /app/.bundle/gems/ruby/1.8/gems/rake-0.9.2/lib/rake/application.rb:59:in
> `run' /app/.bundle/gems/ruby/1.8/gems/rake-0.9.2/bin/rake:32
> /app/.bundle/gems/ruby/1.8/bin/rake:19:in `load'
> /app/.bundle/gems/ruby/1.8/bin/rake:19 Tasks: TOP => gps_start
Delayed::Jobs::enqueue
不接受选项哈希。它需要1到3个参数,顺序如下:
- 工作
- 优先级(可选)
- 在时间运行(可选)
#to_i
,试图将其转换为优先级,从而导致出现错误。如果您只想指定一次运行,您可以为优先级传入nil
,它将使用默认优先级:
Delayed::Job.enqueue(Scraper.new, nil, 5.minutes.from_now)
这取决于您使用的作业的版本。最新版本确实需要一个选项散列,带有支持的键:priority和:run_at。但是,如果您使用的是较旧版本的延迟作业,它的工作原理与答案1类似。当我按上面的方式调用enqueue时,我的延迟作业版本给出了以下内容:[不推荐]将多个参数传递给
#enqueue
是不推荐的。通过:priority和:run_传递散列。看起来它开始只接受一个选项散列。