I have a rails app in which I have a method where I send a lot of emails. I would like to perform this action asynchronously
. To do it I've tried to use Sidekiq
, but I can't get it to work properly - it doesn't send any emails.
我有一个rails应用程序,我有一个方法,我发送了很多电子邮件。我想异步执行此操作。要做到这一点,我试图使用Sidekiq,但我不能让它正常工作 - 它不发送任何电子邮件。
Sending email worked before, so I'm certain that my email settings is set ut correctly.
以前发送电子邮件,所以我确定我的电子邮件设置已正确设置。
In my gemfile
I have this:
在我的gemfile中我有这个:
gem 'sidekiq'
And I have run bundle install
. I have also install redis
, followed the instructions on RailsCasts #366.
我已经运行了bundle install。我还安装了redis,遵循RailsCasts#366上的说明。
I have started sidekiq
with the following command: bundle exec sidekiq
, this resulted in what can be seen in the image below:
我已经使用以下命令启动了sidekiq:bundle exec sidekiq,这导致了下图中可以看到的内容:
In application.rb
I have the following:
在application.rb中我有以下内容:
config.active_job.queue_adapter = :sidekiq
And I try to send the emails like this:
我尝试发送这样的电子邮件:
Mailer.deliver_new_competition_notification(member.user, @competition).deliver_later!
I don't get any errors, but the emails never gets sent.
我没有收到任何错误,但电子邮件永远不会被发送。
So, have I missed something?
那么,我错过了什么吗?
2 个解决方案
#1
37
You need to bootup sidekiq with the mailer queue for it to pick up these jobs:
您需要使用邮件程序队列启动sidekiq以获取这些作业:
bundle exec sidekiq -q default -q mailers
The Sidekiq Wiki goes over the scenarios in detail here.
Sidekiq Wiki详细介绍了这些场景。
#2
4
Also you can modify the config/sidekiq.yml:
你也可以修改config / sidekiq.yml:
---
:concurrency: 25
:pidfile: ./tmp/pids/sidekiq.pid
:logfile: ./log/sidekiq.log
:queues:
- default
- mailers
And run sidekiq -C config/sidekiq.yml
并运行sidekiq -C config / sidekiq.yml
#1
37
You need to bootup sidekiq with the mailer queue for it to pick up these jobs:
您需要使用邮件程序队列启动sidekiq以获取这些作业:
bundle exec sidekiq -q default -q mailers
The Sidekiq Wiki goes over the scenarios in detail here.
Sidekiq Wiki详细介绍了这些场景。
#2
4
Also you can modify the config/sidekiq.yml:
你也可以修改config / sidekiq.yml:
---
:concurrency: 25
:pidfile: ./tmp/pids/sidekiq.pid
:logfile: ./log/sidekiq.log
:queues:
- default
- mailers
And run sidekiq -C config/sidekiq.yml
并运行sidekiq -C config / sidekiq.yml