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
|
|
|
|
|
2015-07-07 16:11:20 -04:00
|
|
|
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
|
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
|