Rails + Devise + delayed_job?

AnA*_*ice 19 ruby-on-rails heroku devise ruby-on-rails-3

我在Heroku上使用Devise有一个Rails 3应用程序.问题是我正在发送带有Sendgrid的电子邮件,而且电子邮件递送速度很慢,这会让应用程序挂起.所以我有兴趣使用delayed_job在后台排队电子邮件,因此我的应用程序响应用户.

Devise如何与delayed_job一起使用?设置Devise以使用delayed_job的任何方法?

Vee*_*Vee 24

来自Robert May:https://gist.github.com/659514

将其添加到config/initializers目录中的文件:

module Devise
  module Models
    module Confirmable
      handle_asynchronously :send_confirmation_instructions
    end

    module Recoverable
      handle_asynchronously :send_reset_password_instructions
    end

    module Lockable
      handle_asynchronously :send_unlock_instructions
    end
  end
end
Run Code Online (Sandbox Code Playgroud)

  • 将该代码添加到`config/initializers`目录中的某个file.rb中. (3认同)

小智 12

根据Devise wiki页面,devise-async gem将为您处理此问题.它支持delayed_job,resque和sidekiq.


hrd*_*rbl 6

我发现以上都不适合我.我正在使用Devise 2.0.4和Rails 3.2.2以及delayed_job_active_record 0.3.2

设计实际上谈论在代码中的注释中做这样的事情的方式是覆盖User类中的方法.因此,我这样解决了它,它完美地工作:

应用程序/模型/ User.rb

def send_on_create_confirmation_instructions
  Devise::Mailer.delay.confirmation_instructions(self)
end
def send_reset_password_instructions
  Devise::Mailer.delay.reset_password_instructions(self)
end
def send_unlock_instructions
  Devise::Mailer.delay.unlock_instructions(self)
end
Run Code Online (Sandbox Code Playgroud)

  • 如果你在最新的Devise中查看send_reset_password_instructions的代码:#Reset reset password token并通过电子邮件def send_reset_password_instructions generate_reset_password_token发送重置密码说明!if should_generate_reset_token?self.devise_mailer.reset_password_instructions(self).deliver end上面的建议导致密码令牌无法生成. (2认同)