mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
change the perform
instrumentation to wrap perform_now
instead of the perform
method.
This commit is contained in:
parent
0c6f32a9f9
commit
b8baeb44ae
6 changed files with 21 additions and 8 deletions
|
@ -1,6 +1,7 @@
|
|||
* Skip logging rescuable exceptions which are defined in rescue_from/retry_on/discard_on.
|
||||
* Change the `perform` instrumentation to wrap `perform_now` instead of the `perform` method to stop logging rescuable exceptions defined with `rescue_from`.
|
||||
|
||||
*Hu Hailin*
|
||||
|
||||
|
||||
|
||||
Please check [6-1-stable](https://github.com/rails/rails/blob/6-1-stable/activejob/CHANGELOG.md) for previous changes.
|
||||
|
|
|
@ -51,6 +51,15 @@ module ActiveJob
|
|||
rescue_with_handler(exception) || raise
|
||||
end
|
||||
|
||||
def perform_now_with_instrument
|
||||
tag_logger(self.class.name, self.job_id) do
|
||||
instrument :perform, &method(:perform_now_without_instrument)
|
||||
end
|
||||
end
|
||||
|
||||
alias_method :perform_now_without_instrument, :perform_now
|
||||
alias_method :perform_now, :perform_now_with_instrument
|
||||
|
||||
def perform(*)
|
||||
fail NotImplementedError
|
||||
end
|
||||
|
|
|
@ -10,8 +10,8 @@ module ActiveJob
|
|||
end
|
||||
|
||||
around_perform do |_, block|
|
||||
instrument :perform_start
|
||||
instrument :perform, &block
|
||||
ActiveSupport::Notifications.instrument \
|
||||
"perform_start.active_job", { adapter: queue_adapter, job: self }, &block
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -54,10 +54,8 @@ module ActiveJob
|
|||
job = event.payload[:job]
|
||||
ex = event.payload[:exception_object]
|
||||
if ex
|
||||
unless job.class.rescue_handlers.any? { |handler| handler[0] == event.payload[:exception][0] }
|
||||
error do
|
||||
"Error performing #{job.class.name} (Job ID: #{job.job_id}) from #{queue_name(event)} in #{event.duration.round(2)}ms: #{ex.class} (#{ex.message}):\n" + Array(ex.backtrace).join("\n")
|
||||
end
|
||||
error do
|
||||
"Error performing #{job.class.name} (Job ID: #{job.job_id}) from #{queue_name(event)} in #{event.duration.round(2)}ms: #{ex.class} (#{ex.message}):\n" + Array(ex.backtrace).join("\n")
|
||||
end
|
||||
elsif event.payload[:aborted]
|
||||
error do
|
||||
|
|
|
@ -12,7 +12,6 @@ module ActiveJob
|
|||
class_attribute :log_arguments, instance_accessor: false, default: true
|
||||
|
||||
around_enqueue { |_, block| tag_logger(&block) }
|
||||
around_perform { |job, block| tag_logger(job.class.name, job.job_id, &block) }
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -260,6 +260,12 @@ class LoggingTest < ActiveSupport::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
def test_job_no_error_logging_on_rescuable_job
|
||||
perform_enqueued_jobs { RescueJob.perform_later "david" }
|
||||
assert_match(/Performing RescueJob \(Job ID: .*?\) from .*? with arguments:.*david/, @logger.messages)
|
||||
assert_no_match(/Error performing RescueJob \(Job ID: .*?\) from .*? in .*ms: ArgumentError \(Hair too good\):\n.*\brescue_job\.rb:\d+:in `perform'/, @logger.messages)
|
||||
end
|
||||
|
||||
def test_enqueue_retry_logging
|
||||
perform_enqueued_jobs do
|
||||
RetryJob.perform_later "DefaultsError", 2
|
||||
|
|
Loading…
Reference in a new issue