Alex Rivera | Logout

Rails + Devise + delayed_job?

Asked 2010-11-08T16:05:11.590
19

I have a Rails 3 App using Devise on Heroku. Problem is I'm sending emails with Sendgrid and email delivery is slow, it makes the app hang. So I'm interested in using delayed_job to queue the email delivery in the background so my app is responsive to the user.

How can Devise be used with delayed_job? Any way to setup Devise to use delayed_job?

Edit
Report

1 Answer

1

I'm not sure Devise provides an easy way to do backgrounding of email delivery. However there are ways to be able to do that with DelayedJoy. DelyedJob provides a function "handle_asynchronously" which if injected into the DeviseMailer can ensure that deliveries happen in the background.

Try this in your config/application.rb

config.after_initialize do 
  ::DeviseMailer.handle_asynchronously :deliver_confirmation_instructions 
  # or
  ::DeviseMailer.handle_asynchronously :deliver!
end

You will need to experiment with that. You could also try to inherit the DeviseMailer and set it to deliver asynchronously in an initializer in config/initializer/devise_mailer_setup.rb or something to that effect.

answered 2010-12-27T08:19:28.987

Your Answer