Skip to content

Commit

Permalink
Don't include enqueuing info when job wasn't enqueued
Browse files Browse the repository at this point in the history
  • Loading branch information
dustinbrownman committed Oct 11, 2023
1 parent c8c95f4 commit be9d0f0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
4 changes: 3 additions & 1 deletion activejob/lib/active_job/log_subscriber.rb
Expand Up @@ -76,7 +76,9 @@ def enqueue_all(event)
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
Expand Down
9 changes: 9 additions & 0 deletions activejob/test/cases/logging_test.rb
Expand Up @@ -144,6 +144,15 @@ def test_perform_job_logging
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)
Expand Down

0 comments on commit be9d0f0

Please sign in to comment.