0

我在 Rails 应用程序中使用 delay_job 时遇到问题。如果我试图通过 Struct 传递一个简单的(整数)id,我的工作就会失败。这是目前工作的样子:

  class EventJob < Struct.new(:event_id)
    def perform
      # TODO
    end
  end

perform 的主体现在是空的。执行这样的作业时出现以下失败错误:

Delayed::Job.enqueue(EventJob.new(1))

这是错误消息:

Job failed to load: undefined method `members' for #. Handler: "--- !ruby/struct:EventJob \nevent_id: 1\n"
C:/Ruby193/lib/ruby/gems/1.9.1/gems/delayed_job-3.0.3/lib/delayed/backend/base.rb:86:in `rescue in payload_object'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/delayed_job-3.0.3/lib/delayed/backend/base.rb:84:in `payload_object'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/delayed_job-3.0.3/lib/delayed/backend/base.rb:94:in `block in invoke_job'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/delayed_job-3.0.3/lib/delayed/lifecycle.rb:60:in `call'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/delayed_job-3.0.3/lib/delayed/lifecycle.rb:60:in `block in initialize'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/delayed_job-3.0.3/lib/delayed/lifecycle.rb:65:in `call'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/delayed_job-3.0.3/lib/delayed/lifecycle.rb:65:in `execute'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/delayed_job-3.0.3/lib/delayed/lifecycle.rb:38:in `run_callbacks'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/delayed_job-3.0.3/lib/delayed/backend/base.rb:91:in `invoke_job'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/delayed_job-3.0.3/lib/delayed/worker.rb:182:in `block (2 levels) in run'
C:/Ruby193/lib/ruby/1.9.1/timeout.rb:68:in `timeout'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/delayed_job-3.0.3/lib/delayed/worker.rb:182:in `block in run'
C:/Ruby193/lib/ruby/1.9.1/benchmark.rb:295:in `realtime'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/delayed_job-3.0.3/lib/delayed/worker.rb:181:in `run'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/delayed_job-3.0.3/lib/delayed/worker.rb:238:in `block in reserve_and_run_one_job'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/delayed_job-3.0.3/lib/delayed/lifecycle.rb:60:in `call'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/delayed_job-3.0.3/lib/delayed/lifecycle.rb:60:in `block in initialize'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/delayed_job-3.0.3/lib/delayed/lifecycle.rb:65:in `call'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/delayed_job-3.0.3/lib/delayed/lifecycle.rb:65:in `execute'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/delayed_job-3.0.3/lib/delayed/lifecycle.rb:38:in `run_callbacks'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/delayed_job-3.0.3/lib/delayed/worker.rb:238:in `reserve_and_run_one_job'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/delayed_job-3.0.3/lib/delayed/worker.rb:166:in `block in work_off'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/delayed_job-3.0.3/lib/delayed/worker.rb:165:in `times'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/delayed_job-3.0.3/lib/delayed/worker.rb:165:in `work_off'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/delayed_job-3.0.3/lib/delayed/worker.rb:133:in `block (4 levels) in start'
C:/Ruby193/lib/ruby/1.9.1/benchmark.rb:295:in `realtime'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/delayed_job-3.0.3/lib/delayed/worker.rb:132:in `block (3 levels) in start'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/delayed_job-3.0.3/lib/delayed/lifecycle.rb:60:in `call'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/delayed_job-3.0.3/lib/delayed/lifecycle.rb:60:in `block in initialize'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/delayed_job-3.0.3/lib/delayed/lifecycle.rb:65:in `call'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/delayed_job-3.0.3/lib/delayed/lifecycle.rb:65:in `execute'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/delayed_job-3.0.3/lib/delayed/lifecycle.rb:38:in `run_callbacks'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/delayed_job-3.0.3/lib/delayed/worker.rb:129:in `block (2 levels) in start'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/delayed_job-3.0.3/lib/delayed/worker.rb:128:in `loop'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/delayed_job-3.0.3/lib/delayed/worker.rb:128:in `block in start'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/delayed_job-3.0.3/lib/delayed/plugins/clear_locks.rb:7:in `call'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/delayed_job-3.0.3/lib/delayed/plugins/clear_locks.rb:7:in `block (2 levels) in '
C:/Ruby193/lib/ruby/gems/1.9.1/gems/delayed_job-3.0.3/lib/delayed/lifecycle.rb:78:in `call'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/delayed_job-3.0.3/lib/delayed/lifecycle.rb:78:in `block (2 levels) in add'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/delayed_job-3.0.3/lib/delayed/lifecycle.rb:60:in `call'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/delayed_job-3.0.3/lib/delayed/lifecycle.rb:60:in `block in initialize'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/delayed_job-3.0.3/lib/delayed/lifecycle.rb:78:in `call'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/delayed_job-3.0.3/lib/delayed/lifecycle.rb:78:in `block in add'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/delayed_job-3.0.3/lib/delayed/lifecycle.rb:65:in `call'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/delayed_job-3.0.3/lib/delayed/lifecycle.rb:65:in `execute'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/delayed_job-3.0.3/lib/delayed/lifecycle.rb:38:in `run_callbacks'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/delayed_job-3.0.3/lib/delayed/worker.rb:127:in `start'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/delayed_job-3.0.3/lib/delayed/tasks.rb:9:in `block (2 levels) in '
C:/Ruby193/lib/ruby/1.9.1/rake/task.rb:205:in `call'
C:/Ruby193/lib/ruby/1.9.1/rake/task.rb:205:in `block in execute'
C:/Ruby193/lib/ruby/1.9.1/rake/task.rb:200:in `each'
C:/Ruby193/lib/ruby/1.9.1/rake/task.rb:200:in `execute'
C:/Ruby193/lib/ruby/1.9.1/rake/task.rb:158:in `block in invoke_with_call_chain'
C:/Ruby193/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
C:/Ruby193/lib/ruby/1.9.1/rake/task.rb:151:in `invoke_with_call_chain'
C:/Ruby193/lib/ruby/1.9.1/rake/task.rb:144:in `invoke'
C:/Ruby193/lib/ruby/1.9.1/rake/application.rb:116:in `invoke_task'
C:/Ruby193/lib/ruby/1.9.1/rake/application.rb:94:in `block (2 levels) in top_level'
C:/Ruby193/lib/ruby/1.9.1/rake/application.rb:94:in `each'
C:/Ruby193/lib/ruby/1.9.1/rake/application.rb:94:in `block in top_level'
C:/Ruby193/lib/ruby/1.9.1/rake/application.rb:133:in `standard_exception_handling'
C:/Ruby193/lib/ruby/1.9.1/rake/application.rb:88:in `top_level'
C:/Ruby193/lib/ruby/1.9.1/rake/application.rb:66:in `block in run'
C:/Ruby193/lib/ruby/1.9.1/rake/application.rb:133:in `standard_exception_handling'
C:/Ruby193/lib/ruby/1.9.1/rake/application.rb:63:in `run'
C:/Ruby193/bin/rake:32:in `'

如果我删除 Struct.new(:event_id) 它正在执行 peform 方法。奇怪的是我没有一个叫做“成员”的方法。但是 Struct 有一个名为 members 的方法。delay_job 和 Struct 之间是否存在某种兼容性问题?

谢谢!

4

2 回答 2

0

我相信你的 YAML 引擎有些奇怪。检查 YAML::Parser 常量是什么。它应该是 Psych::Parser。您应该能够执行:

YAML.load "--- !ruby/struct:EventJob \nevent_id: 1\n"

在您的 irb 控制台中。

于 2012-10-15T10:16:40.003 回答
0

好的,不知道是什么导致了这个问题。我刚刚回到我的项目的旧备份版本,现在它似乎又可以工作了。抱歉,我无法提供有关它的更多详细信息,除非它在某处发生故障。

于 2012-10-24T07:17:45.503 回答