Skip to content

DelayedJob and ActiveJob Integration

Wout edited this page Oct 20, 2020 · 1 revision

By default emails are sent synchronously. You can send them asynchronously by using the delayed_job gem or Rails' ActiveJob.

After implementing the delayed_job or ActiveJob into your project add the code below at the end of the config/initializers/sorcery.rb file. After that all emails will be sent asynchronously.

module Sorcery
  module Model
    module InstanceMethods
      def generic_send_email(method, mailer)
        config = sorcery_config

        # DelayedJob
        mail = config.send(mailer).delay.send(config.send(method), self)

        # ActiveJob
        mail = config.send(mailer).send(config.send(method), self).deliver_later
      end
    end
  end
end