首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >后台邮件通过sidekiq和devise-async发送,队列被填满但邮件不被处理

后台邮件通过sidekiq和devise-async发送,队列被填满但邮件不被处理
EN

Stack Overflow用户
提问于 2012-11-19 18:35:52
回答 3查看 2.9K关注 0票数 11

我目前正在构建一个rails平台,我已经使用devise进行了身份验证,现在我想使用sidekiq将默认的devise电子邮件移到后台进程中。为此,我使用了devise-async,并完成了以下操作:

添加了devise_async.rb文件:

代码语言:javascript
复制
#config/initializers/devise_async.rb
Devise::Async.backend = :sidekiq

向devise模型添加了async命令:

代码语言:javascript
复制
#user.rb
devise :database_authenticatable, :async #etc.

gems的版本如下:

代码语言:javascript
复制
Devise 2.1.2
Devise-async 0.4.0
Sidekiq 2.5.3

我遇到的问题是,电子邮件在sidekiq队列中传递,但工作人员从不执行发送电子邮件。我也看过devise async not working with sidekiq,他似乎也有同样的问题。但是我不认为我对hostname命令有什么问题。

对这个问题有什么想法吗?

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2012-11-21 17:21:59

答案很简单。您只需通过使用bundle exec sidekiq -q mailer启动sidekiq,告诉sidekiq使用mailer队列。这样邮件队列将被处理,没有选项sidekiq将简单地依赖于default队列。

票数 19
EN

Stack Overflow用户

发布于 2019-05-10 02:13:48

在2019年,由于 device -async不是最新的,并且如果您已完成ActiveJob和sidekiq设置,则最简单的解决方案是覆盖与事务邮件相关的devicedocumentation here实例方法,如图所示的here

代码语言:javascript
复制
class User < ApplicationRecord
  # whatever association you have here
  devise :database_authenticatable, :confirmable
  after_commit :send_pending_devise_notifications
  # whatever methods you have here

 protected
  def send_devise_notification(notification, *args)
    if new_record? || changed?
      pending_devise_notifications << [notification, args]
    else
      render_and_send_devise_message(notification, *args)
    end
  end

  private

  def send_pending_devise_notifications
    pending_devise_notifications.each do |notification, args|
      render_and_send_devise_message(notification, *args)
    end

    pending_devise_notifications.clear
  end

  def pending_devise_notifications
    @pending_devise_notifications ||= []
  end

  def render_and_send_devise_message(notification, *args)
    message = devise_mailer.send(notification, self, *args)

    # Deliver later with Active Job's `deliver_later`
    if message.respond_to?(:deliver_later)
      message.deliver_later
    # Remove once we move to Rails 4.2+ only, as `deliver` is deprecated.
    elsif message.respond_to?(:deliver_now)
      message.deliver_now
    else
      message.deliver
    end
  end

end
票数 0
EN

Stack Overflow用户

发布于 2021-06-11 12:45:40

现在,Devise https://github.com/heartcombo/devise#activejob-integration支持此功能

代码语言:javascript
复制
class User < ApplicationRecord

  devise ...

  # Override devise: send emails in the background
  def send_devise_notification(notification, *args)
    devise_mailer.send(notification, self, *args).deliver_later
  end

end
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13452020

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档