为什么Sidekiq 4无法正确使用邮件?

时间:2016-03-17 09:24:45

标签: ruby-on-rails ruby-on-rails-4 actionmailer sidekiq

我正在使用rails 4.2.5sidekiq 4.0.2sidekiq_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中没有队列:

no queues in sidekiq UI O_o

但是UI会看到应该初始化的队列:

first tab

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?

1 个答案:

答案 0 :(得分:1)

Gemfilegem '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用于异步邮件传递。