Skip to content

Commit bf3b921

Browse files
authored
move Rollbar::ActiveJob out of the plugin (#1149)
1 parent 063b416 commit bf3b921

File tree

1 file changed

+33
-33
lines changed

1 file changed

+33
-33
lines changed

lib/rollbar/plugins/active_job.rb

+33-33
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,45 @@
1-
Rollbar.plugins.define('active_job') do
2-
dependency { !configuration.disable_monkey_patch }
3-
dependency { !configuration.disable_action_mailer_monkey_patch }
1+
module Rollbar
2+
# Report any uncaught errors in a job to Rollbar and reraise
3+
module ActiveJob
4+
def self.included(base)
5+
base.send :rescue_from, Exception do |exception|
6+
job_data = {
7+
:job => self.class.name,
8+
:use_exception_level_filters => true
9+
}
410

5-
execute do
6-
module Rollbar
7-
# Report any uncaught errors in a job to Rollbar and reraise
8-
module ActiveJob
9-
def self.included(base)
10-
base.send :rescue_from, Exception do |exception|
11-
job_data = {
12-
:job => self.class.name,
13-
:use_exception_level_filters => true
14-
}
11+
# When included in ActionMailer, the handler is called twice.
12+
# This detects the execution that has the expected state.
13+
if defined?(ActionMailer::Base) && self.class.ancestors.include?(ActionMailer::Base)
14+
job_data[:action] = action_name
15+
job_data[:params] = @params
1516

16-
# When included in ActionMailer, the handler is called twice.
17-
# This detects the execution that has the expected state.
18-
if defined?(ActionMailer::Base) && self.class.ancestors.include?(ActionMailer::Base)
19-
job_data[:action] = action_name
20-
job_data[:params] = @params
17+
Rollbar.error(exception, job_data)
2118

22-
Rollbar.error(exception, job_data)
23-
24-
# This detects other supported integrations.
25-
elsif defined?(arguments)
26-
job_data[:arguments] = \
27-
if self.class.respond_to?(:log_arguments?) && !self.class.log_arguments?
28-
arguments.map(&Rollbar::Scrubbers.method(:scrub_value))
29-
else
30-
arguments
31-
end
32-
job_data[:job_id] = job_id if defined?(job_id)
33-
34-
Rollbar.error(exception, job_data)
19+
# This detects other supported integrations.
20+
elsif defined?(arguments)
21+
job_data[:arguments] = \
22+
if self.class.respond_to?(:log_arguments?) && !self.class.log_arguments?
23+
arguments.map(&Rollbar::Scrubbers.method(:scrub_value))
24+
else
25+
arguments
3526
end
27+
job_data[:job_id] = job_id if defined?(job_id)
3628

37-
raise exception
38-
end
29+
Rollbar.error(exception, job_data)
3930
end
31+
32+
raise exception
4033
end
4134
end
35+
end
36+
end
4237

38+
Rollbar.plugins.define('active_job') do
39+
dependency { !configuration.disable_monkey_patch }
40+
dependency { !configuration.disable_action_mailer_monkey_patch }
41+
42+
execute do
4343
if defined?(ActiveSupport) && ActiveSupport.respond_to?(:on_load)
4444
ActiveSupport.on_load(:action_mailer) do
4545
if defined?(ActionMailer::MailDeliveryJob) # Rails >= 6.0

0 commit comments

Comments
 (0)