Rails的Delayed

编程入门 行业动态 更新时间:2024-10-28 20:17:01
本文介绍了Rails的Delayed_job失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我刚刚开始研究使用delay_job gem。

I am just beginning to look into using the delayed_job gem.

为了测试它,我在欢迎电子邮件功能中添加了 delayed,并从

To test it, I added "delayed" to the welcome email function and changed that call from

UserMailer.welcome_email(self).deliver

UserMailer.delay.welcome_email(self)

这在用户模型after_create中调用。函数执行后,我看到一个条目显示在delay_job表中。现在,当我在命令行上运行 rake jobs:work时,任务开始但出现以下错误

This is called inside the User model after_create. I see an entry show up in the delayed_job table after the function executes. Now when I run "rake jobs:work" on command line the task starts but gives errors as below

[Worker(host:Sanjay-PC pid:7008)] Starting job worker [Worker(host:Sanjay-PC pid:7008)] Class#welcome_email failed with NoMethodError: undefined method `welcome_email' for #<Class:0x4871d60> - 0 failed attempts [Worker(host:Sanjay-PC pid:7008)] 1 jobs processed at 0.0939 j/s, 1 failed ...

认为如果我将welcome_email方法声明更改为Class方法,则为

Thinking that if I changed the welcome_email method declaration to a Class method as

def self.welcome_email(user)

(在前面添加self。)可能会有所帮助。但是当我运行rake job:work时,出现以下错误

(added self. in front) that might help. But then when I run rake jobs:work I get the following error

rake aborted! undefined method `welcome_email' for class `UserMailer' C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.5/lib/active_support/core_ext/module/aliasing.rb:31:in `alias_method' C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.5/lib/active_support/core_ext/module/aliasing.rb:31:in `alias_method_chain' C:/Ruby192/lib/ruby/gems/1.9.1/gems/delayed_job-2.1.4/lib/delayed/message_sending.rb:50:in `handle_asynchronously' c:/mgn/mgn-r3/app/mailers/user_mailer.rb:10:in `<class:UserMailer>' c:/mgn/mgn-r3/app/mailers/user_mailer.rb:1:in `<top (required)>' C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:454:in `load' <Stack truncated>

现在似乎知道该类为UserMailer,但是却不知道该类的方法welcome_email。

It seems to now know the class as UserMailer but it somehow doesn't see the class method welcome_email.

我在Rails 3.0.5,Ruby 1.9.2p180上并且已安装的delay_job gem为2.1.4-在Windows上

I am on Rails 3.0.5, Ruby 1.9.2p180 and the installed delayed_job gem is 2.1.4 - on Windows

似乎在任何地方都找不到任何相关的答案。

Can't seem to find any related answers anywhere.

感谢您的想法。

-S

根据@pjammer的请求添加UserMailer代码

Adding UserMailer code per @pjammer's request

class UserMailer < ActionMailer::Base default :from => "from@example" def welcome_email(user) @user = user @url = "example/login" mail(:to => user.email, :subject => "Welcome to My Awesome Site") end end

推荐答案

只需使用

UserMailer.delay.welcome_email(self).deliver

而不是

UserMailer.welcome_email(self).delay.deliver

更多推荐

Rails的Delayed

本文发布于:2023-05-27 03:03:31,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/275490.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Rails   Delayed

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!