Skip to content

Commit

Permalink
Fix Active Job log message to correctly report a job failed to enqueu…
Browse files Browse the repository at this point in the history
…e when the adapter raises an `ActiveJob::EnqueueError`
  • Loading branch information
bensheldon committed Sep 2, 2023
1 parent fea9ad3 commit b1b7deb
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
5 changes: 5 additions & 0 deletions activejob/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
* Fix Active Job log message to correctly report a job failed to enqueue
when the adapter raises an `ActiveJob::EnqueueError`.

*Ben Sheldon*

* Add `after_discard` method.

This method lets job authors define a block which will be run when a job is about to be discarded. For example:
Expand Down
4 changes: 2 additions & 2 deletions activejob/lib/active_job/log_subscriber.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class LogSubscriber < ActiveSupport::LogSubscriber # :nodoc:

def enqueue(event)
job = event.payload[:job]
ex = event.payload[:exception_object]
ex = event.payload[:exception_object] || job.enqueue_error

if ex
error do
Expand All @@ -28,7 +28,7 @@ def enqueue(event)

def enqueue_at(event)
job = event.payload[:job]
ex = event.payload[:exception_object]
ex = event.payload[:exception_object] || job.enqueue_error

if ex
error do
Expand Down
14 changes: 14 additions & 0 deletions activejob/test/cases/logging_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,20 @@ def test_enqueue_in_job_logging
skip
end

def test_enqueue_log_when_enqueue_error_is_set
EnqueueErrorJob.disable_test_adapter

EnqueueErrorJob.perform_later
assert_match(/Failed enqueuing EnqueueErrorJob to EnqueueError\(default\): ActiveJob::EnqueueError \(There was an error enqueuing the job\)/, @logger.messages)
end

def test_enqueue_at_log_when_enqueue_error_is_set
EnqueueErrorJob.disable_test_adapter

EnqueueErrorJob.set(wait: 1.hour).perform_later
assert_match(/Failed enqueuing EnqueueErrorJob to EnqueueError\(default\): ActiveJob::EnqueueError \(There was an error enqueuing the job\)/, @logger.messages)
end

def test_for_tagged_logger_support_is_consistent
set_logger ::Logger.new(nil)
OverriddenLoggingJob.perform_later "Dummy"
Expand Down

0 comments on commit b1b7deb

Please sign in to comment.