1

我通过以下代码将 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
4

1 回答 1

0

我刚刚在安装了 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 传递给ImportContact工作人员而不是整个 CSV 文本的时候了。这将缓解您当前遇到的问题,并帮助您避免使用大量文本列使数据库膨胀。

于 2013-04-16T21:49:34.923 回答