Sha256: 62215fc648bbb855e144de5e54e1ae3d675c1f10483ea68e973031f81d8c8400

Contents?: true

Size: 1.38 KB

Versions: 97

Compression:

Stored size: 1.38 KB

Contents

# frozen_string_literal: true

require "active_job"

module ActionMailer
  # The <tt>ActionMailer::MailDeliveryJob</tt> class is used when you
  # want to send emails outside of the request-response cycle. It supports
  # sending either parameterized or normal mail.
  #
  # Exceptions are rescued and handled by the mailer class.
  class MailDeliveryJob < ActiveJob::Base # :nodoc:
    queue_as { ActionMailer::Base.deliver_later_queue_name }

    rescue_from StandardError, with: :handle_exception_with_mailer_class

    def perform(mailer, mail_method, delivery_method, args:, kwargs: nil, params: nil)
      mailer_class = params ? mailer.constantize.with(params) : mailer.constantize
      message = if kwargs
        mailer_class.public_send(mail_method, *args, **kwargs)
      else
        mailer_class.public_send(mail_method, *args)
      end
      message.send(delivery_method)
    end

    private
      # "Deserialize" the mailer class name by hand in case another argument
      # (like a Global ID reference) raised DeserializationError.
      def mailer_class
        if mailer = Array(@serialized_arguments).first || Array(arguments).first
          mailer.constantize
        end
      end

      def handle_exception_with_mailer_class(exception)
        if klass = mailer_class
          klass.handle_exception exception
        else
          raise exception
        end
      end
  end
end

Version data entries

97 entries across 93 versions & 6 rubygems

Version Path
actionmailer-6.1.6.1 lib/action_mailer/mail_delivery_job.rb
actionmailer-6.0.5.1 lib/action_mailer/mail_delivery_job.rb
actionmailer-6.0.5 lib/action_mailer/mail_delivery_job.rb
actionmailer-6.1.6 lib/action_mailer/mail_delivery_job.rb
actionmailer-7.0.3 lib/action_mailer/mail_delivery_job.rb
actionmailer-7.0.2.4 lib/action_mailer/mail_delivery_job.rb
actionmailer-6.1.5.1 lib/action_mailer/mail_delivery_job.rb
actionmailer-6.0.4.8 lib/action_mailer/mail_delivery_job.rb
actionmailer-6.1.5 lib/action_mailer/mail_delivery_job.rb
actionmailer-7.0.2.3 lib/action_mailer/mail_delivery_job.rb
actionmailer-6.1.4.7 lib/action_mailer/mail_delivery_job.rb
actionmailer-6.0.4.7 lib/action_mailer/mail_delivery_job.rb
actionmailer-7.0.2.2 lib/action_mailer/mail_delivery_job.rb
actionmailer-6.1.4.6 lib/action_mailer/mail_delivery_job.rb
actionmailer-6.0.4.6 lib/action_mailer/mail_delivery_job.rb
actionmailer-6.0.4.5 lib/action_mailer/mail_delivery_job.rb
actionmailer-6.1.4.5 lib/action_mailer/mail_delivery_job.rb
actionmailer-7.0.2.1 lib/action_mailer/mail_delivery_job.rb
actionmailer-7.0.2 lib/action_mailer/mail_delivery_job.rb
actionmailer-7.0.1 lib/action_mailer/mail_delivery_job.rb