refactor(mailer): extract dolist logic into its concern
This commit is contained in:
parent
ae7e3cf887
commit
6615165b2e
4 changed files with 17 additions and 10 deletions
|
@ -1,4 +1,5 @@
|
|||
class ApplicationMailer < ActionMailer::Base
|
||||
include MailerDolistConcern
|
||||
include MailerMonitoringConcern
|
||||
|
||||
helper :application # gives access to all helpers defined within `application_helper`.
|
||||
|
|
15
app/mailers/concerns/mailer_dolist_concern.rb
Normal file
15
app/mailers/concerns/mailer_dolist_concern.rb
Normal file
|
@ -0,0 +1,15 @@
|
|||
module MailerDolistConcern
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
before_action :add_dolist_header
|
||||
|
||||
# mandatory for dolist
|
||||
# used for tracking in Dolist UI
|
||||
# the delivery_method is yet unknown (:balancer)
|
||||
# so we add the dolist header for everyone
|
||||
def add_dolist_header
|
||||
headers['X-Dolist-Message-Name'] = action_name
|
||||
end
|
||||
end
|
||||
end
|
|
@ -2,8 +2,6 @@ module MailerMonitoringConcern
|
|||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
before_action :add_dolist_header
|
||||
|
||||
# Intercept & log any error, then re-raise so job will retry.
|
||||
# NOTE: rescue_from order matters, later matchers are tried first.
|
||||
rescue_from StandardError, with: :log_and_raise_delivery_error
|
||||
|
@ -21,14 +19,6 @@ module MailerMonitoringConcern
|
|||
end
|
||||
end
|
||||
|
||||
# mandatory for dolist
|
||||
# used for tracking in Dolist UI
|
||||
# the delivery_method is yet unknown (:balancer)
|
||||
# so we add the dolist header for everyone
|
||||
def add_dolist_header
|
||||
headers['X-Dolist-Message-Name'] = action_name
|
||||
end
|
||||
|
||||
def log_and_raise_delivery_error(exception)
|
||||
EmailEvent.create_from_message!(message, status: "dispatch_error")
|
||||
Sentry.capture_exception(exception, extra: { to: message.to, subject: message.subject })
|
||||
|
|
|
@ -3,6 +3,7 @@ class DeviseUserMailer < Devise::Mailer
|
|||
helper :application # gives access to all helpers defined within `application_helper`.
|
||||
helper MailerHelper
|
||||
include Devise::Controllers::UrlHelpers # Optional. eg. `confirmation_url`
|
||||
include MailerDolistConcern
|
||||
include MailerMonitoringConcern
|
||||
layout 'mailers/layout'
|
||||
before_action :add_delivery_method, if: :forced_delivery?
|
||||
|
|
Loading…
Reference in a new issue