2017-07-23 11:17:16 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-08-06 13:01:31 -04:00
|
|
|
require "active_job"
|
2014-08-13 17:50:38 -04:00
|
|
|
|
|
|
|
module ActionMailer
|
2014-10-26 01:17:51 -04:00
|
|
|
# The <tt>ActionMailer::DeliveryJob</tt> class is used when you
|
|
|
|
# want to send emails outside of the request-response cycle.
|
2016-05-13 20:43:48 -04:00
|
|
|
#
|
|
|
|
# Exceptions are rescued and handled by the mailer class.
|
2014-12-23 02:42:16 -05:00
|
|
|
class DeliveryJob < ActiveJob::Base # :nodoc:
|
2015-01-18 17:34:01 -05:00
|
|
|
queue_as { ActionMailer::Base.deliver_later_queue_name }
|
2014-08-13 17:50:38 -04:00
|
|
|
|
2016-05-13 20:43:48 -04:00
|
|
|
rescue_from StandardError, with: :handle_exception_with_mailer_class
|
|
|
|
|
2018-11-30 17:33:35 -05:00
|
|
|
before_perform do
|
|
|
|
ActiveSupport::Deprecation.warn <<~MSG.squish
|
|
|
|
Sending mail with DeliveryJob and Parameterized::DeliveryJob
|
|
|
|
is deprecated and will be removed in Rails 6.1.
|
|
|
|
Please use MailDeliveryJob instead.
|
|
|
|
MSG
|
|
|
|
end
|
|
|
|
|
|
|
|
def perform(mailer, mail_method, delivery_method, *args) #:nodoc:
|
|
|
|
mailer.constantize.public_send(mail_method, *args).send(delivery_method)
|
2014-08-13 17:50:38 -04:00
|
|
|
end
|
2020-01-19 00:29:32 -05:00
|
|
|
ruby2_keywords(:perform) if respond_to?(:ruby2_keywords, true)
|
2016-05-13 20:43:48 -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
|
2014-08-13 17:50:38 -04:00
|
|
|
end
|
|
|
|
end
|