Rails: delayed_job mail not sending

匿名 (未验证) 提交于 2019-12-03 08:59:04

问题:

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.

I installed the gem

 gem 'delayed_job_active_record' 

I generated the table and ran the migrations, as instructed

$ rails generate delayed_job:active_record $ rake db:migrate 

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) 

I did

 def send_welcome_email      #UserMailer.welcome_email(self).deliver  <-- original code that worked     UserMailer.delay.welcome_email(self)            end 

but the mail isn't sending. It was working before I tried to use delayed_job...

Can someone clarify for a novice...?

回答1:

Did you start at least 1 delayed_job worker?

rake jobs:work 

Actually, when you call delayon 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.

So you still need something that will browse all your DelayedJobentries and run them one by one and that thing is the rake task (worker) shown above.

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.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!