簡體   English   中英

delayed_job入隊方法的新錯誤

[英]New error with delayed_job enqueue method

這是我的模特:

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_job版本。 實際上,最新版本需要一個選項哈希,支持密鑰:priority和:run_at。 但是,如果您使用的是舊版本的delayed_job,則其效果與Answer 1相同。

Delayed::Jobs::enqueue不接受選項哈希。 它按以下順序需要1到3個參數:

  • 工作
  • 優先級(可選)
  • 運行時間(可選)

因為您傳入了第二個參數的選項哈希,所以它在其上調用#to_i以嘗試將其轉換為優先級,這會導致您獲得的錯誤。 如果只想指定運行時間,則可以傳入nil作為優先級,它將使用默認優先級:

Delayed::Job.enqueue(Scraper.new, nil, 5.minutes.from_now)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM