Don't include enqueuing info when job wasn't enqueued

This commit is contained in:
Dustin Brown 2023-10-03 00:30:03 +00:00
parent c8c95f424e
commit be9d0f05a4
2 changed files with 12 additions and 1 deletions

View File

@ -76,7 +76,9 @@ module ActiveJob
def perform_start(event)
info do
job = event.payload[:job]
"Performing #{job.class.name} (Job ID: #{job.job_id}) from #{queue_name(event)} enqueued at #{job.enqueued_at.utc.iso8601(9)}" + args_info(job)
enqueue_info = job.enqueued_at.present? ? " enqueued at #{job.enqueued_at.utc.iso8601(9)}" : ""
"Performing #{job.class.name} (Job ID: #{job.job_id}) from #{queue_name(event)}" + enqueue_info + args_info(job)
end
end
subscribe_log_level :perform_start, :info

View File

@ -144,6 +144,15 @@ class LoggingTest < ActiveSupport::TestCase
end
end
def test_perform_job_logging_when_job_is_not_enqueued
perform_enqueued_jobs do
LoggingJob.perform_now "Dummy"
assert_match(/Performing LoggingJob \(Job ID: .*?\) from .*? with arguments:.*Dummy/, @logger.messages)
assert_no_match(/enqueued at /, @logger.messages)
end
end
def test_perform_job_log_error_when_callback_chain_is_halted
subscribed { AbortBeforeEnqueueJob.perform_now }
assert_match(/Error performing AbortBeforeEnqueueJob.* a before_perform callback halted/, @logger.messages)