Delayed_job:NoMethodError:未定义方法“my_method_without_delay”

发布于 2024-11-29 08:58:41 字数 665 浏览 0 评论 0原文

使用rails 2.3.11和delayed_job 2.0.4作为gem,在使用handle_asynchronously时出现错误:

在我的ActionMailer模型中,我删除了my_method并在声明后立即添加了“handle_asynchronously:my_method”:

class MailSender < ActionMailer::Base
    def my_method
        ...
    end
    handle_asynchronously :my_method
end

调用时MailSender.deliver_my_method 任务已正确添加到队列中。但是,当尝试处理它时,它失败并显示错误消息:

undefined method `rappel_email_without_delay' for #<YAML::Object:0x1034b85f8>

使用 MailSender.delay.deliver_my_method 进行延迟正在工作,并且任务已正确处理 - 但我宁愿使用 handle_asynchronously联合国我的模型,以确保邮件始终在后台发送......

Using rails 2.3.11 and delayed_job 2.0.4 as a gem I get an error when using handle_asynchronously :

In my ActionMailer model, I delcared my_method and added ' handle_asynchronously :my_method' right after the declaration :

class MailSender < ActionMailer::Base
    def my_method
        ...
    end
    handle_asynchronously :my_method
end

When calling MailSender.deliver_my_method the task is correctly added to the queue. But when trying to process it, it fails with the error message :

undefined method `rappel_email_without_delay' for #<YAML::Object:0x1034b85f8>

Delaying with MailSender.delay.deliver_my_method is working and the task correctly processed - But i'd rather use handle_asynchronously un my model to ensure mail are always sent in the background...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

彼岸花ソ最美的依靠 2024-12-06 08:58:41

您需要使用以下命令重新启动工作进程

耙子作业:工作

You need to restart the worker processes using

rake jobs:work

高速公鹿 2024-12-06 08:58:41

在3.2.3中也有这个问题。

通过在每次代码更改后重新启动 DJ 进程来修复此问题。

Also had this problem in 3.2.3.

Fixed it by restarting the DJ process after every code change.

表情可笑 2024-12-06 08:58:41

您仍然可以使用handle_asynchronously 宏进行声明,但是使用ActionMailer 调用延迟作业的语法有点不同。

# without delayed_job
MailSender.my_method.deliver

# with delayed_job
MailSerder.delay.my_method

这是从旧版本的自述文件中提取的,但它不在当前版本中,所以也许延迟作业的新版本可以解决这个细微差别。

You can still declare using the handle_asynchronously macro, but the syntax for calling delayed jobs with ActionMailer is a bit different.

# without delayed_job
MailSender.my_method.deliver

# with delayed_job
MailSerder.delay.my_method

This was pulled from an older version of the README, but it's not in the current one, so maybe a newer version of delayed jobs worked around this nuance.

铁轨上的流浪者 2024-12-06 08:58:41

我遇到了同样的问题,最终遇到了以下帖子 。基本上,delayed_job 工作人员似乎在解组非 ActiveRecord 对象时遇到困难。对我有用的快速修复方法是要求您的类位于初始化程序或environment.rb中,例如

# config/environment.rb
...
require 'mail_sender'

I ran into the same problem and eventually came across the following post. Basically the delayed_job worker seems to have difficulties unmarshalling non-ActiveRecord objects. The quick fix which worked for me is to require your class in an initializer or environment.rb, e.g.

# config/environment.rb
...
require 'mail_sender'
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文