簡體   English   中英

延遲工作時出錯。 無法解析YAML

[英]Error with delayed job. Couldn't Parse YAML

我通過以下代碼將csv文件傳遞給延遲的工作。

csv_text = IO.read(params[:emails_import].tempfile.to_path, :encoding => 'UTF-8').gsub(" ", "")
csv_text = csv_text.gsub("\n\n", "\n")
Delayed::Job.enqueue ImportContact.new(@list.id, csv_text), :queue => "import-list-#{@list.id}"

我正在通過領班收到以下錯誤消息。 任何想法可能導致此問題嗎? 我認為該錯誤可能在csv文件中,但是我不確定在哪里/什么引起了問題。

[Worker(host:ubuntu pid:22678)] Starting job worker
16:50:22 worker.1 |   SQL (129.4ms)  UPDATE `delayed_jobs` SET locked_at = '2013-04-16 20:50:22', locked_by = 'host:ubuntu pid:22678' WHERE (id = 121 and (locked_at is null or locked_at < '2013-04-16 16:50:22') and (run_at <= '2013-04-16 20:50:22'))
16:50:22 worker.1 |   SQL (96.4ms)  UPDATE `delayed_jobs` SET locked_by = null, locked_at = null WHERE (locked_by = 'host:ubuntu pid:22678')
16:50:22 worker.1 | rake aborted!
16:50:22 worker.1 | couldn't parse YAML at line 6709 column 4
16:50:22 worker.1 | /home/cory/.rvm/gems/ruby-1.9.2-p320@postpourri/gems/delayed_job-3.0.3/lib/delayed/backend/base.rb:84:in `payload_object'
16:50:22 worker.1 | /home/cory/.rvm/gems/ruby-1.9.2-p320@postpourri/gems/delayed_job-3.0.3/lib/delayed/backend/base.rb:71:in `name'
16:50:22 worker.1 | /home/cory/.rvm/gems/ruby-1.9.2-p320@postpourri/gems/delayed_job-3.0.3/lib/delayed/worker.rb:230:in `handle_failed_job'
16:50:22 worker.1 | /home/cory/.rvm/gems/ruby-1.9.2-p320@postpourri/gems/delayed_job-3.0.3/lib/delayed/worker.rb:191:in `block in run'
16:50:22 worker.1 | /home/cory/.rvm/gems/ruby-1.9.2-p320@postpourri/gems/delayed_job-3.0.3/lib/delayed/lifecycle.rb:60:in `call'
16:50:22 worker.1 | /home/cory/.rvm/gems/ruby-1.9.2-p320@postpourri/gems/delayed_job-3.0.3/lib/delayed/lifecycle.rb:60:in `block in initialize'
16:50:22 worker.1 | /home/cory/.rvm/gems/ruby-1.9.2-p320@postpourri/gems/delayed_job-3.0.3/lib/delayed/lifecycle.rb:65:in `call'
16:50:22 worker.1 | /home/cory/.rvm/gems/ruby-1.9.2-p320@postpourri/gems/delayed_job-3.0.3/lib/delayed/lifecycle.rb:65:in `execute'
16:50:22 worker.1 | /home/cory/.rvm/gems/ruby-1.9.2-p320@postpourri/gems/delayed_job-3.0.3/lib/delayed/lifecycle.rb:38:in `run_callbacks'
16:50:22 worker.1 | /home/cory/.rvm/gems/ruby-1.9.2-p320@postpourri/gems/delayed_job-3.0.3/lib/delayed/worker.rb:191:in `rescue in run'
16:50:22 worker.1 | /home/cory/.rvm/gems/ruby-1.9.2-p320@postpourri/gems/delayed_job-3.0.3/lib/delayed/worker.rb:181:in `run'
16:50:22 worker.1 | /home/cory/.rvm/gems/ruby-1.9.2-p320@postpourri/gems/delayed_job-3.0.3/lib/delayed/worker.rb:238:in `block in reserve_and_run_one_job'
16:50:22 worker.1 | /home/cory/.rvm/gems/ruby-1.9.2-p320@postpourri/gems/delayed_job-3.0.3/lib/delayed/lifecycle.rb:60:in `call'
16:50:22 worker.1 | /home/cory/.rvm/gems/ruby-1.9.2-p320@postpourri/gems/delayed_job-3.0.3/lib/delayed/lifecycle.rb:60:in `block in initialize'
16:50:22 worker.1 | /home/cory/.rvm/gems/ruby-1.9.2-p320@postpourri/gems/delayed_job-3.0.3/lib/delayed/lifecycle.rb:65:in `call'
16:50:22 worker.1 | /home/cory/.rvm/gems/ruby-1.9.2-p320@postpourri/gems/delayed_job-3.0.3/lib/delayed/lifecycle.rb:65:in `execute'
16:50:22 worker.1 | /home/cory/.rvm/gems/ruby-1.9.2-p320@postpourri/gems/delayed_job-3.0.3/lib/delayed/lifecycle.rb:38:in `run_callbacks'
16:50:22 worker.1 | /home/cory/.rvm/gems/ruby-1.9.2-p320@postpourri/gems/delayed_job-3.0.3/lib/delayed/worker.rb:238:in `reserve_and_run_one_job'
16:50:22 worker.1 | /home/cory/.rvm/gems/ruby-1.9.2-p320@postpourri/gems/delayed_job-3.0.3/lib/delayed/worker.rb:166:in `block in work_off'
16:50:22 worker.1 | /home/cory/.rvm/gems/ruby-1.9.2-p320@postpourri/gems/delayed_job-3.0.3/lib/delayed/worker.rb:165:in `times'
16:50:22 worker.1 | /home/cory/.rvm/gems/ruby-1.9.2-p320@postpourri/gems/delayed_job-3.0.3/lib/delayed/worker.rb:165:in `work_off'
16:50:22 worker.1 | /home/cory/.rvm/gems/ruby-1.9.2-p320@postpourri/gems/delayed_job-3.0.3/lib/delayed/worker.rb:133:in `block (4 levels) in start'
16:50:22 worker.1 | /home/cory/.rvm/gems/ruby-1.9.2-p320@postpourri/gems/delayed_job-3.0.3/lib/delayed/worker.rb:132:in `block (3 levels) in start'
16:50:22 worker.1 | /home/cory/.rvm/gems/ruby-1.9.2-p320@postpourri/gems/delayed_job-3.0.3/lib/delayed/lifecycle.rb:60:in `call'
16:50:22 worker.1 | /home/cory/.rvm/gems/ruby-1.9.2-p320@postpourri/gems/delayed_job-3.0.3/lib/delayed/lifecycle.rb:60:in `block in initialize'
16:50:22 worker.1 | /home/cory/.rvm/gems/ruby-1.9.2-p320@postpourri/gems/delayed_job-3.0.3/lib/delayed/lifecycle.rb:65:in `call'
16:50:22 worker.1 | /home/cory/.rvm/gems/ruby-1.9.2-p320@postpourri/gems/delayed_job-3.0.3/lib/delayed/lifecycle.rb:65:in `execute'
16:50:22 worker.1 | /home/cory/.rvm/gems/ruby-1.9.2-p320@postpourri/gems/delayed_job-3.0.3/lib/delayed/lifecycle.rb:38:in `run_callbacks'
16:50:22 worker.1 | /home/cory/.rvm/gems/ruby-1.9.2-p320@postpourri/gems/delayed_job-3.0.3/lib/delayed/worker.rb:129:in `block (2 levels) in start'
16:50:22 worker.1 | /home/cory/.rvm/gems/ruby-1.9.2-p320@postpourri/gems/delayed_job-3.0.3/lib/delayed/worker.rb:128:in `loop'
16:50:22 worker.1 | /home/cory/.rvm/gems/ruby-1.9.2-p320@postpourri/gems/delayed_job-3.0.3/lib/delayed/worker.rb:128:in `block in start'
16:50:22 worker.1 | /home/cory/.rvm/gems/ruby-1.9.2-p320@postpourri/gems/delayed_job-3.0.3/lib/delayed/plugins/clear_locks.rb:7:in `call'
16:50:22 worker.1 | /home/cory/.rvm/gems/ruby-1.9.2-p320@postpourri/gems/delayed_job-3.0.3/lib/delayed/plugins/clear_locks.rb:7:in `block (2 levels) in <class:ClearLocks>'
16:50:22 worker.1 | /home/cory/.rvm/gems/ruby-1.9.2-p320@postpourri/gems/delayed_job-3.0.3/lib/delayed/lifecycle.rb:78:in `call'
16:50:22 worker.1 | /home/cory/.rvm/gems/ruby-1.9.2-p320@postpourri/gems/delayed_job-3.0.3/lib/delayed/lifecycle.rb:78:in `block (2 levels) in add'
16:50:22 worker.1 | /home/cory/.rvm/gems/ruby-1.9.2-p320@postpourri/gems/delayed_job-3.0.3/lib/delayed/lifecycle.rb:60:in `call'
16:50:22 worker.1 | /home/cory/.rvm/gems/ruby-1.9.2-p320@postpourri/gems/delayed_job-3.0.3/lib/delayed/lifecycle.rb:60:in `block in initialize'
16:50:22 worker.1 | /home/cory/.rvm/gems/ruby-1.9.2-p320@postpourri/gems/delayed_job-3.0.3/lib/delayed/lifecycle.rb:78:in `call'
16:50:22 worker.1 | /home/cory/.rvm/gems/ruby-1.9.2-p320@postpourri/gems/delayed_job-3.0.3/lib/delayed/lifecycle.rb:78:in `block in add'
16:50:22 worker.1 | /home/cory/.rvm/gems/ruby-1.9.2-p320@postpourri/gems/delayed_job-3.0.3/lib/delayed/lifecycle.rb:65:in `call'
16:50:22 worker.1 | /home/cory/.rvm/gems/ruby-1.9.2-p320@postpourri/gems/delayed_job-3.0.3/lib/delayed/lifecycle.rb:65:in `execute'
16:50:22 worker.1 | /home/cory/.rvm/gems/ruby-1.9.2-p320@postpourri/gems/delayed_job-3.0.3/lib/delayed/lifecycle.rb:38:in `run_callbacks'
16:50:22 worker.1 | /home/cory/.rvm/gems/ruby-1.9.2-p320@postpourri/gems/delayed_job-3.0.3/lib/delayed/worker.rb:127:in `start'
16:50:22 worker.1 | /home/cory/.rvm/gems/ruby-1.9.2-p320@postpourri/gems/delayed_job-3.0.3/lib/delayed/tasks.rb:9:in `block (2 levels) in <top (required)>'
16:50:22 worker.1 | /home/cory/.rvm/gems/ruby-1.9.2-p320@postpourri/bin/ruby_noexec_wrapper:14:in `eval'
16:50:22 worker.1 | /home/cory/.rvm/gems/ruby-1.9.2-p320@postpourri/bin/ruby_noexec_wrapper:14:in `<main>'
16:50:22 worker.1 | Tasks: TOP => jobs:work
16:50:22 worker.1 | (See full trace by running task with --trace)
16:50:22 worker.1 | exited with code 1
16:50:22 system   | sending SIGTERM to all processes
SIGTERM received

我只是在安裝了Delayed :: Job的全新Rails應用中運行了此代碼(從您提供的內容進行了修改):

class List
  attr_accessor :id
end
@list = List.new
@list.id = 123

class ImportContact
  def initialize(list_id, csv_text)
    @list_id = list_id
    @csv_text = csv_text
  end

  def perform
    puts @list_id
    puts @csv_text.length
  end
end

csv_text = IO.read('test_2000_import_contacts.csv', :encoding => 'UTF-8').gsub(" ", "")
csv_text = csv_text.gsub("\n\n", "\n")
Delayed::Job.enqueue ImportContact.new(@list.id, csv_text), :queue => "import-list-#{@list.id}"

當我運行bundle exec rake jobs:work ,一切都正確進行了,這使我相信YAML編碼或解碼要導入的文件的方式存在問題。

特別是我會跑

yaml = Delayed::Job.find(121).handler
File.open('job-121.yml', 'w') { |f| f.write(yaml) }

並檢查line 6709 column 4附近的文件。

但是,這可能是時候建議您將文件存儲在S3之類的文件中,然后將URL而不是整個CSV文本傳遞給ImportContact工作程序。 這將緩解當前遇到的問題,並幫助您避免使用巨大的文本列使數據庫膨脹。

暫無
暫無

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

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