Rails:delay_job邮件未发送 [英] Rails: delayed_job mail not sending
问题描述
我正在尝试在以下位置使用delay_job gem https://github.com/collectiveidea/delayed_job Rails 3.2在后台发送邮件。
I'm trying to use delayed_job gem https://github.com/collectiveidea/delayed_job in Rails 3.2 to send a mail in the background.
我安装了宝石
gem 'delayed_job_active_record'
我按照指示生成了表并运行了迁移
I generated the table and ran the migrations, as instructed
$ rails generate delayed_job:active_record
$ rake db:migrate
注意在Rails 3中有一些针对邮件发件人的特殊说明
Noting that there are special instructions for mailers in Rails 3
# without delayed_job
Notifier.signup(@user).deliver
# with delayed_job
Notifier.delay.signup(@user)
我做了
def send_welcome_email
#UserMailer.welcome_email(self).deliver <-- original code that worked
UserMailer.delay.welcome_email(self)
end
,但邮件未发送。在我尝试使用delay_job之前,它一直在工作。
but the mail isn't sending. It was working before I tried to use delayed_job...
有人可以为新手澄清吗??
Can someone clarify for a novice...?
推荐答案
您是否至少雇用1名 delayed_job
工人?
Did you start at least 1 delayed_job
worker?
rake jobs:work
实际上,当您在对象上调用 delay
时,您只是在排队工作。这意味着将在 DelayedJob
表内创建一个新条目,该表包含与您的工作相关的所有元数据。
Actually, when you call delay
on an object, you are only queuing a job. Which means that a new entry will be created inside the DelayedJob
table that contains all the metadata associated with your job.
因此,您仍然需要能够浏览所有 DelayedJob
条目并逐个运行它们的东西,这就是上面显示的rake任务(工作人员)。
So you still need something that will browse all your DelayedJob
entries and run them one by one and that thing is the rake task (worker) shown above.
对于生产而言,这取决于您将应用程序部署在何处。在Heroku上,您只需要指定需要的工人数( Worker dynos
),它们就会自动启动。
For production, it depends where you are deploying your application. On Heroku you only have to specify how many workers (Worker dynos
) you need and they will start automatically.
这篇关于Rails:delay_job邮件未发送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!