NoMethodError与delay_job(collectiveidea gem) [英] NoMethodError with delayed_job (collectiveidea gem)

查看:81
本文介绍了NoMethodError与delay_job(collectiveidea gem)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更新:此问题有一个修补程序: https://github.com / collectiveidea / delayed_job / commit / 023444424166ba2ce011bfe2d47954e79edf6798

UPDATE: There's been a patch for this issue: https://github.com/collectiveidea/delayed_job/commit/023444424166ba2ce011bfe2d47954e79edf6798

更新2:对于任何在Heroku上遇到此问题的人,我已经发现降级到Rake 0.8.7并使用延迟作业版本2.1.4可以工作,而延迟作业v3则不行(尽管使用补丁程序它可以在本地运行)。这是在Bamboo-mri-1.9.2堆栈上。

我正在尝试在Rails 3.1.0应用程序本地实现delay_job。我运行迁移并
安装了gem文件:

I am trying to implement delayed_job on a rails 3.1.0 app locally. I ran the migration and installed the gem files:

gem 'delayed_job'
gem 'delayed_job_active_record'

按照collectionidea github( https://github.com/collectiveidea/delayed_job )。我从控制器发出延迟呼叫,如下所示:

Following the documentation on the collectiveidea github (https://github.com/collectiveidea/delayed_job). I am making the delay call from my controller as follows:

EventMailer.delay.event_message_email(current_user, @event_message)

这会导致将任务添加到作业表中,但是当我运行rake作业时:work会记录以下错误:

This causes the task to be added to the job table but when I run rake jobs:work it logs the following error:

Class#event_message_email failed with NoMethodError: undefined method `event_message_email' for Class:Class - 6 failed attempts

我看过SO上的其他delay_job NoMethod错误问题,但没有一个解决此特定错误或提供解决方案。 collectionidea页面提到,这种没有传递方法调用的格式是如何设置Rails 3邮件程序的一种技巧,所以我想知道此文档是否可能有些过时,以及是否有一种新的方法来调用邮件程序方法?

I've looked at the the other delayed_job NoMethod error questions on SO but none address this specific error or provide a solution to it. The collectiveidea page mentions that this format without the deliver method call is a hack for how Rails 3 mailers are setup, so I'm wondering if perhaps this documentation may be some how outdated, and if there is a new way to call mailer methods?

更新:也可以无延迟地调用mailer方法,效果很好,并且我在默认的rails服务器上运行它,因此,collectionidea常见问题中提到的Thin问题不适用。谢谢

Update: also calling the mailer method without delay works fine, and I am running it on the default rails server so the issue with Thin mentioned in the collectiveidea faq does not apply. Thanks

推荐答案

我通过切换到delay_job(DJ)版本2.1.2解决了这个问题。

I fixed this problem by switching to delayed_job (DJ) version 2.1.2.

我正在使用:
rvm
ruby​​ 1.8.7(2010-01-10 patchlevel 249)
rails 3.0.9

I am using: rvm ruby 1.8.7 (2010-01-10 patchlevel 249) rails 3.0.9

Gemfile:
gem delayed_job,'2.1.2'

Gemfile: gem "delayed_job", '2.1.2'

在此之前,我尝试使用最新版本的delay_job:
gem delayed_job,:git =>'git://github.com/collectiveidea/delayed_job.git'
对我来说是v3.0.0.pre

Before this I tried to use the latest version of delayed_job: gem "delayed_job", :git => 'git://github.com/collectiveidea/delayed_job.git' for me it was v3.0.0.pre

但是:
rails产生了delay_job
没有产生迁移文件。我手动创建的。然后在 rake db:migrate之后,我有了用于存储delay_job队列的表。然后,当我认为所有错误都必须正确运行时,我遇到了相同的错误。

But: rails generate delayed_job didn't generate migrations file. I created it manually. Then after 'rake db:migrate' I've got the table for storing delayed_job queue. And then, when I was thinking that all must be worked correctly, I've got the same error.

当我尝试查找此错误的来源时,在我发现delay_jobs的任务没有正确保存。以下是 delayed_jobs表中字段 handler的摘录:

When I tried to find the source of this error, in 'delayed_jobs' table I have found that delayed_job's tasks are incorrectly saved. Here is snippet from field 'handler' in 'delayed_jobs' table:

--- !ruby/object:Delayed::PerformableMailer 
object: !ruby/class Notifier

我知道,delay_job通过Struct获取所有任务类,因此应使用'!ruby / object'的'!ruby / struct'标头istead保存
这是正确保存的任务的代码段:

As I know, delayed_job gets all tasks through Struct class, so the task should be saved with '!ruby/struct' header isntead of '!ruby/object' Here is the snippet of correctly saved task:

--- !ruby/struct:Delayed::PerformableMailer 
object: !ruby/class Notifier

要检查这一点,我在控制台中停止了delaed_job进程。然后我调用了一种将DJ的任务放入数据库的方法:

To check this I stopped delaed_job process in console. Then I called some method to put DJ's task to DB:

Notifier.delay.some_email(current_user, @event_message)

然后我在 handler字段中将!ruby / object手动替换为!ruby / struct。
然后我开始DJ的 rake jobs:work,它告诉我邮件已成功发送。

Then I manually replaced '!ruby/object' by '!ruby/struct' in 'handler' field. Then I started DJ 'rake jobs:work', it said me that mail was succesfully sent.

但是:
-这项任务并未从DJ的表
中删除-并且邮件也没有到达收件人

But: - this task wasn't be deleted from DJ's table - and mail doesn't get to the recipient

所以我认为这是新版本的delay_job中的错误。我切换到DJ'2.1.2',它对我来说很好。

So I've decided that it is a bug in new version of delayed_job. I switched to DJ '2.1.2' and it's worked for me fine.

P.S .:对不起,我的英语:)

P.S.: Sorry for my English :)

这篇关于NoMethodError与delay_job(collectiveidea gem)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆