[英]Resque_mailer undefined method 'perform' for mailer class
I'am trying to send email using Resque and the Resque_mailer gem, but the sending email jobs are failing after they are queued. 我正在尝试使用Resque和Resque_mailer gem发送电子邮件,但是发送电子邮件作业排队后失败。 I have googled, stackoverflowed, and tested many different code implementations and nothing has worked so far. 我已经用Google搜索,stackoverflowed和测试了许多不同的代码实现,但到目前为止没有任何工作。
I have the following implementation: 我有以下实现:
Versions: rails (3.2.6) resque (1.21.0) resque_mailer (2.1.0) 版本:rails(3.2.6)resque(1.21.0)resque_mailer(2.1.0)
Controller code: 控制器代码:
def send_newsletter
User.find_in_batches(:batch_size => 1000) do |users|
users.each { |user| AdminMailer.newsletter(user.email).deliver }
end
end
Mailer code: 邮件代码:
class AdminMailer < ActionMailer::Base
include Resque::Mailer
def newsletter(user_email)
mail(:to => user_email, :subject => "New Feature", :from => "noreply@example.com")
end
end
The jobs are getting queued (I can see them in the web interface in the mailer queue), but are failing. 作业正在排队(我可以在邮件队列的Web界面中看到它们),但是失败了。 Here is the failing error message: 这是失败的错误消息:
Exception: NoMethodError
Error: undefined method `perform' for AdminMailer:Class
This is strange because in my local development machine the jobs are getting completed without errors. 这很奇怪,因为在我的本地开发机器中,作业可以顺利完成而没有错误。 Is there something I am missing to get it to work in production with engineyard? 使它在Engineyard中投入生产需要我缺少什么吗?
I have run other resque jobs that do not include sending email or using resque_email just fine. 我已经运行了其他resque作业,这些作业不包括发送电子邮件或使用resque_email都很好。
I would really appreciate any kind of help, thanks in advance! 非常感谢您的帮助,在此先感谢您!
Fixed the issue: 解决了该问题:
The issue was that in production, the Resque processes were not restarting correctly when I deployed my app to EngineYard. 问题是在生产中,当我将应用程序部署到EngineYard时,Resque进程无法正确重新启动。
EngineYard has deployment hooks where you can run code at certain points during the deployment process. EngineYard具有部署挂钩,您可以在其中在部署过程中的某些点运行代码。
In the after_symlink
deployment hook, the correct code to run is: sudo "monit restart all -g app_name_resque"
. 在after_symlink
部署挂钩中,要运行的正确代码是: sudo "monit restart all -g app_name_resque"
。 Where app_name
is the name of your app. 其中app_name
是您的应用程序的名称。 Also, in the before_restart
deploy hook you need to run: run "sudo monit start all -g fractalresque_resque"
另外,在before_restart
部署挂钩中,您需要运行: run "sudo monit start all -g fractalresque_resque"
This fixed the issue for me! 这为我解决了这个问题!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.