我在 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 之间是否存在某种兼容性问题?
谢谢!