代码之家  ›  专栏  ›  技术社区  ›  cdiamand

延迟作业出错。无法分析YAML

  •  1
  • cdiamand  · 技术社区  · 12 年前

    我通过以下代码将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
    
    1 回复  |  直到 12 年前
        1
  •  0
  •   Benjamin Manns    12 年前

    我刚刚在一个全新的Rails应用程序中运行了这段代码,安装了Delayed::Job(根据您提供的内容进行了修改):

    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文本。这将缓解您当前遇到的问题,并帮助您避免数据库中出现大量文本列。