我正在使用rails 4.2.5
,sidekiq 4.0.2
和sidekiq_mailer 0.0.8
撰写项目。目前我正在开发一种异步发送电子邮件的功能。
所以,这是我的邮件:
class UserMailer < ActionMailer::Base
include Sidekiq::Mailer
sidekiq_options queue: 'mailer', backtrace: true
default from: '<mail_from>'
def one_c_client_problems_email(message)
@message = message
email_subject = "SUBJ"
mail(to: '<mail_to>', subject: email_subject)
end
end
Sidekiq初始化程序:
require 'sidekiq'
require 'sidekiq/web'
Sidekiq::Web.use(Rack::Auth::Basic) do |user, password|
[user, password] == ['<login>', '<pass>']
end
schedule_file = 'config/schedule.yml'
if File.exists?(schedule_file) && Sidekiq.server?
Sidekiq::Cron::Job.load_from_hash YAML.load_file(schedule_file)
end
Sidekiq配置文件:
---
:concurrency: 10
:pidfile: tmp/pids/sidekiq.pid
:logfile: log/sidekiq.log
:queues:
- default
- mailer
(我用bundle exec sidekiq -C config/sidekiq.yml
命令启动了sidekiq)
在application.rb
中,sidekiq配置为默认活动作业适配器:
config.active_job.queue_adapter = :sidekiq
当我尝试从rails控制台发送信件时没有sidekiq:
UserMailer.one_c_client_problems_email('message').deliver!
有效!
当我尝试使用sidekiq发送异步电子邮件时:
UserMailer.one_c_client_problems_email('message').deliver
什么都没发生......
P.S。定期工作正常,非邮件工作正常。 为什么不工作?请帮助!
Sidekiq UI中没有队列:
但是UI会看到应该初始化的队列:
Sidekiq日志是空的(当我运行sidekiq时,sidekiq -q default -q mailers
控制台输出也是空的)。我在日志中看到的内容:
2016-03-17T09:26:33.926Z 1852 TID-ovlvb5ofs INFO: Booting Sidekiq 4.0.2 with redis options {:url=>nil}
2016-03-17T09:26:33.954Z 1852 TID-ovlvb5ofs INFO: Cron Jobs - add job with name: 1C Client. Update users to our db. Every hour
2016-03-17T09:26:33.956Z 1852 TID-ovlvb5ofs INFO: Cron Jobs - add job with name: Survey Reminder. Remind users about unfilled surveys. 9AM every day
2016-03-17T09:26:33.995Z 1852 TID-ovlvb5ofs INFO: Cron Jobs - add job with name: 1C Client. Update users to our db. Every hour
2016-03-17T09:26:33.997Z 1852 TID-ovlvb5ofs INFO: Cron Jobs - add job with name: Survey Reminder. Remind users about unfilled surveys. 9AM every day
2016-03-17T09:26:36.245Z 1852 TID-ovlvb5ofs INFO: Running in ruby 2.2.4p230 (2015-12-16 revision 53155) [x86_64-darwin15]
2016-03-17T09:26:36.245Z 1852 TID-ovlvb5ofs INFO: See LICENSE and the LGPL-3.0 for licensing details.
2016-03-17T09:26:36.245Z 1852 TID-ovlvb5ofs INFO: Upgrade to Sidekiq Pro for more features and support: http://sidekiq.org
2016-03-17T09:26:36.245Z 1852 TID-ovlvb5ofs INFO: Starting processing, hit Ctrl-C to stop
为什么日志Booting Sidekiq 4.0.2 with redis options {:url=>nil}
Redis网址为nil
?为什么sidekiq没有看到redis?
答案 0 :(得分:1)
Gemfile
行gem 'rspec-sidekiq'
应位于group :test
。
这个gem更改了sidekiq配置,并且在Sidekiq 4.X.X
版本中运行不佳。
group :test do
gem 'rspec-sidekiq'
end
但我仍然不知道为什么日志中的redis网址为nil
...
此外,sidekiq 4.0.2
不需要sidekiq_mailer
gem用于异步邮件传递。