我在一个rails 4应用程序中设置了sidekiq,用于发送电子邮件和处理后台作业.我还设计了我正在使用devise_async和一个典型的联系表格邮箱.我正在使用Gmail发送电子邮件.
如果我删除sidekiq,它通过gmail(设计和联系形式)正常发送电子邮件,但是当我启用它时,它不起作用(既不是devise_async也不是联系表单). Sidekiq显示后台工作开始并且成功完成(我也通过sinatra应用程序看到它已被处理),但电子邮件从未被传递过.
在开发中,控制台显示发送的电子邮件(两者都使用devise_async和联系人窗体,因为它们与sidekiq成功处理).
我已经尝试过:
>我已经添加了sidekiq的rails4的github分支(我也试过了主)
>我已经更新并检查redis版本是否大于
2.4(这是2.6.14)
>我正在运行sidekiq与bundle exec sidekiq
但没有任何工作.我使用的是ruby 2.0.0-p247.
我也在这个应用程序中设置了sidekiq的图像处理,并且在开发和生产中都是完美的.
def send_message @message = Message.new(message_params) if @message.save ContactMailer.delay.contact_form(@message.id) end end
我的邮件:
def contact_form(message_id) message = Message.where(id: message_id).first @email = message.email @message = message.text mail(to: "myemail@gmail.com",subject: "Message from contact form") end
和我的生产配置(它在没有sidekiq的情况下工作):
config.action_mailer.delivery_method = :smtp ActionMailer::Base.smtp_settings = { :address => "smtp.gmail.com",:port => 587,:domain => "gmail.com",:authentication => "plain",:enable_starttls_auto => true,:user_name => "myusername",:password => "mypassword" } config.action_mailer.default_url_options = { :host => "mydomain.com" }
这里有一个典型的sidekiq队列:
/home/john/.rvm/gems/ruby-2.0.0-p247@cluey/bundler/gems/sidekiq-4ed6eba8aff1/lib/sidekiq/rails.rb:14: warning: toplevel constant Queue referenced by Sidekiq::Client::Queue 2013-07-19T09:47:56Z 20112 TID-1a5mkc INFO: Booting Sidekiq 2.5.2 with Redis at redis://localhost:6379/0 2013-07-19T09:47:56Z 20112 TID-1a5mkc INFO: Running in ruby 2.0.0p247 (2013-06-27 revision 41674) [i686-linux] 2013-07-19T09:47:56Z 20112 TID-1a5mkc INFO: See LICENSE and the LGPL-3.0 for licensing details. 2013-07-19T09:47:56Z 20112 TID-1a5mkc INFO: Starting processing,hit Ctrl-C to stop 2013-07-19T09:48:11Z 20112 TID-1u2z02 Devise::Async::Backend::Sidekiq JID-4a7e66a14deab112191e4b49 INFO: start 2013-07-19T09:48:12Z 20112 TID-1u2z02 Devise::Async::Backend::Sidekiq JID-4a7e66a14deab112191e4b49 INFO: done: 1.214 sec 2013-07-19T09:48:50Z 20112 TID-1u2z02 Devise::Async::Backend::Sidekiq JID-32191822b789f5b6896a5353 INFO: start 2013-07-19T09:48:51Z 20112 TID-1u2z02 Devise::Async::Backend::Sidekiq JID-32191822b789f5b6896a5353 INFO: done: 0.143 sec 2013-07-19T09:49:29Z 20112 TID-1u2z02 Sidekiq::Extensions::DelayedMailer JID-c1911e0c4b72295dc067d57f INFO: start 2013-07-19T09:49:29Z 20112 TID-1u2z02 Sidekiq::Extensions::DelayedMailer JID-c1911e0c4b72295dc067d57f INFO: done: 0.152 sec
我认为它与actionmailer和sidekiq有关,但我不知道如何调试,一切似乎都工作,但电子邮件从未传递.
解决方法
我发现它,你必须像这样运行sidekiq:
RAILS_ENV=production bundle exec sidekiq -D
在生产中运行.这是与预编译资产相同的问题.