2020-05-12 15:20:07 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require "active_job"
|
|
|
|
|
|
|
|
module ActionMailer
|
|
|
|
# The <tt>ActionMailer::DeliveryJob</tt> class is used when you
|
|
|
|
# want to send emails outside of the request-response cycle.
|
|
|
|
#
|
|
|
|
# Exceptions are rescued and handled by the mailer class.
|
|
|
|
class DeliveryJob < ActiveJob::Base # :nodoc:
|
|
|
|
queue_as { ActionMailer::Base.deliver_later_queue_name }
|
|
|
|
|
|
|
|
rescue_from StandardError, with: :handle_exception_with_mailer_class
|
|
|
|
|
|
|
|
before_perform do
|
|
|
|
ActiveSupport::Deprecation.warn <<~MSG.squish
|
|
|
|
Sending mail with DeliveryJob and Parameterized::DeliveryJob
|
2021-02-04 11:46:53 -05:00
|
|
|
is deprecated and will be removed in Rails 7.0.
|
2020-05-12 15:20:07 -04:00
|
|
|
Please use MailDeliveryJob instead.
|
|
|
|
MSG
|
|
|
|
end
|
|
|
|
|
2021-07-29 17:18:07 -04:00
|
|
|
def perform(mailer, mail_method, delivery_method, *args) # :nodoc:
|
2020-05-12 15:20:07 -04:00
|
|
|
mailer.constantize.public_send(mail_method, *args).send(delivery_method)
|
|
|
|
end
|
2021-04-12 14:49:54 -04:00
|
|
|
ruby2_keywords(:perform)
|
2020-05-12 15:20:07 -04:00
|
|
|
|
|
|
|
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
|