0

Rails アプリケーションでdelayed_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 メソッドが実行されます。奇妙なことに、「members」というメソッドがありません。しかし、Struct には members というメソッドがあります。delayed_job と Struct の間に何らかの互換性の問題がありますか?

ありがとう!

4

2 に答える 2

0

わかりました、何がこの問題を引き起こすのかわかりません。プロジェクトの古いバックアップ バージョンに戻ったところ、再び機能するようになりました。申し訳ありませんが、それ以外の詳細な情報を提供することはできません。

于 2012-10-24T07:17:45.503 に答える
0

あなたの YAML エンジンには何か奇妙なことが起こっていると思います。YAML::Parser 定数を確認してください。Psych::Parser である必要があります。あなたは実行できるはずです:

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

あなたのirbコンソールで。

于 2012-10-15T10:16:40.003 に答える