-
Notifications
You must be signed in to change notification settings - Fork 280
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix ActionMailer plugin to add
rescue_from
to the correct class (#1143
) * make ActiveJob plugin a true plugin, with disable * add rescue_from to ActionMailer::Base, not MailDeliveryJob * test for Rails 6+ first. (DeliveryJob is always defined.) * limit DeliveryJob tests to Rails < 6.x * update test app config for rails 6+ * handle undefined job_id * refactor to test both DeliveryJob and MailDeliveryJob
- Loading branch information
Showing
4 changed files
with
127 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,44 @@ | ||
module Rollbar | ||
# Report any uncaught errors in a job to Rollbar and reraise | ||
module ActiveJob | ||
def self.included(base) | ||
base.send :rescue_from, Exception do |exception| | ||
args = if self.class.respond_to?(:log_arguments?) && !self.class.log_arguments? | ||
arguments.map(&Rollbar::Scrubbers.method(:scrub_value)) | ||
else | ||
arguments | ||
end | ||
Rollbar.plugins.define('active_job') do | ||
dependency { !configuration.disable_monkey_patch } | ||
dependency { !configuration.disable_action_mailer_monkey_patch } | ||
|
||
Rollbar.error(exception, | ||
:job => self.class.name, | ||
:job_id => job_id, | ||
:use_exception_level_filters => true, | ||
:arguments => args) | ||
raise exception | ||
execute do | ||
module Rollbar | ||
# Report any uncaught errors in a job to Rollbar and reraise | ||
module ActiveJob | ||
def self.included(base) | ||
base.send :rescue_from, Exception do |exception| | ||
args = if self.class.respond_to?(:log_arguments?) && !self.class.log_arguments? | ||
arguments.map(&Rollbar::Scrubbers.method(:scrub_value)) | ||
else | ||
arguments | ||
end | ||
|
||
job_data = { | ||
:job => self.class.name, | ||
:use_exception_level_filters => true, | ||
:arguments => args | ||
} | ||
|
||
# job_id isn't present when this is a mailer class. | ||
job_data[:job_id] = job_id if defined?(job_id) | ||
|
||
Rollbar.error(exception, job_data) | ||
raise exception | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
if defined?(ActiveSupport) && ActiveSupport.respond_to?(:on_load) | ||
ActiveSupport.on_load(:action_mailer) do | ||
# Automatically add to ActionMailer::DeliveryJob | ||
if defined?(ActionMailer::DeliveryJob) | ||
ActionMailer::DeliveryJob.send(:include, | ||
Rollbar::ActiveJob) | ||
end | ||
# Rails >= 6.0 | ||
if defined?(ActionMailer::MailDeliveryJob) | ||
ActionMailer::MailDeliveryJob.send(:include, Rollbar::ActiveJob) | ||
if defined?(ActiveSupport) && ActiveSupport.respond_to?(:on_load) | ||
ActiveSupport.on_load(:action_mailer) do | ||
if defined?(ActionMailer::MailDeliveryJob) # Rails >= 6.0 | ||
ActionMailer::Base.send(:include, Rollbar::ActiveJob) | ||
elsif defined?(ActionMailer::DeliveryJob) # Rails < 6.0 | ||
ActionMailer::DeliveryJob.send(:include, | ||
Rollbar::ActiveJob) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters