delayed_job:NoMethodError

这是我的小Rails3控制器:

class HomeController < ApplicationController def index HomeController.delay.do_stuff end def self.do_stuff puts "Hello" end end 

访问index ,作业将正确插入数据库中:

 --- !ruby/struct:Delayed::PerformableMethod object: !ruby/object:Class HomeController method_name: :do_stuff 

问题:当执行bundle exec rake jobs:work ,我得到:

 Class#do_stuff failed with NoMethodError: undefined method `do_stuff' for # 

尽管HomeController.do_stuff工作得很好。 任何的想法?

请参阅文档中的https://github.com/collectiveidea/delayed_job/wiki/Common-problems#wiki-undefined_method_xxx_for_class 。

看来你应该有

..object: !ruby/class HomeController method_name ...

在数据库中,但你有

..object: !ruby/object:Class HomeController method_name ...

代替。 这很糟糕。

甚至delayed_job作者也不知道原因。 它以某种方式取决于您运行的网络服务器。 试试维基的推荐。

我有同样的问题。

我找到了几个讨论,说明当Web作业将作业放入队列时以及稍后执行时,会使用不同的yaml解析器。

有人建议应该使用心理解析器。 有人建议syck。 首先,我尝试了心理,但结果与其他gem的不兼容问题。 所以我选了syck。

我无法理清Web服务器和队列使用的配置文件。 经过大量的实验,我得到了以下配置(所有这些都在文件的顶部):

 #application.rb require File.expand_path('../boot', __FILE__) require 'rails/all' require 'yaml' YAML::ENGINE.yamler= 'syck' # ... 

 #environment.rb require 'yaml' YAML::ENGINE.yamler= 'syck' # ... 

 #boot.rb require 'yaml' YAML::ENGINE.yamler= 'syck' require 'rubygems' # ... 

我使用Ruby 1.9.3,Rails 3.2.8,Webrick,delayed_job 3.0.3

我的情况我的问题主要是因为我将Hash作为参数传递给传递给delayed_job队列的对象。 但经过25条路径后,我得出结论,delayed_job只接受带有整数作为参数的对象。 因此,我将所有参数存储在数据库中,然后将该记录id作为参数传递给delayed_job,在perform函数中,我们可以访问具有该记录id的所有参数,并在获取该数据后删除该记录。

 Delayed::Job.enqueue LeadsJob.new(params[:customer]) # this job will be queued but will never run, this is because of the way Delayed_job serializes and De-serializes the objects. 

而是做这样的事情

 @customer = Customer.create(params[:customer]) Delayed::Job.enqueue LeadsJob.new(@customer.id) 

如果客户详细信息只是传递参数,则删除该函数内的该记录。

如果您需要更多详细信息,请告诉我。

问题可能也是因为Delayed_Job使用的YAML解析器,但我没有试过@Stefan Pettersson提到的那个选项