I have a solution where I be able to send the devise ' stock emails ' the mail messages that are defaultly included in Devise with Delayed jobs. In a async manner. Therefore I use the following code:
/initializers/devise_acync.rb
module Devise
module Models
module Confirmable
alias_method :send_confirmation_instructions_without_delay, :send_confirmation_instructions
handle_asynchronously :send_confirmation_instructions
end
module Recoverable
alias_method :send_reset_password_instructions_without_delay, :send_reset_password_instructions
handle_asynchronously :send_reset_password_instructions
end
module Lockable
alias_method :send_unlock_instructions_without_delay, :send_unlock_instructions
handle_asynchronously :send_unlock_instructions
end
module Invitable
alias_method :deliver_invitation_without_delay, :deliver_invitation
handle_asynchronously :deliver_invitation
end
end
end
In my User Model devise is linked to this model I do
def confirm!
welcome_message
super
end
private
def welcome_message
::Devise.mailer.welcome_instructions(self).deliver
end
The big question that keeps me dazzled: How would I be able to send this welcome message true delayed_job? And how would you add other emails that are custom and not devise included so they get send true delayed_job also?
Have you tried doing it like this:
def welcome_message
::Devise.mailer.delay.welcome_instructions(self)
end