Skip to content

Commit b32c8a0

Browse files
authored
Merge pull request rails#47865 from bensheldon/enqueue-error-message
Fix Active Job log message to correctly report a job failed to enqueue when the adapter raises an `ActiveJob::EnqueueError`
2 parents 42db7f3 + b1b7deb commit b32c8a0

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

activejob/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
* Fix Active Job log message to correctly report a job failed to enqueue
2+
when the adapter raises an `ActiveJob::EnqueueError`.
3+
4+
*Ben Sheldon*
5+
16
* Add `after_discard` method.
27

38
This method lets job authors define a block which will be run when a job is about to be discarded. For example:

activejob/lib/active_job/log_subscriber.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class LogSubscriber < ActiveSupport::LogSubscriber # :nodoc:
88

99
def enqueue(event)
1010
job = event.payload[:job]
11-
ex = event.payload[:exception_object]
11+
ex = event.payload[:exception_object] || job.enqueue_error
1212

1313
if ex
1414
error do
@@ -28,7 +28,7 @@ def enqueue(event)
2828

2929
def enqueue_at(event)
3030
job = event.payload[:job]
31-
ex = event.payload[:exception_object]
31+
ex = event.payload[:exception_object] || job.enqueue_error
3232

3333
if ex
3434
error do

activejob/test/cases/logging_test.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,20 @@ def test_enqueue_in_job_logging
245245
skip
246246
end
247247

248+
def test_enqueue_log_when_enqueue_error_is_set
249+
EnqueueErrorJob.disable_test_adapter
250+
251+
EnqueueErrorJob.perform_later
252+
assert_match(/Failed enqueuing EnqueueErrorJob to EnqueueError\(default\): ActiveJob::EnqueueError \(There was an error enqueuing the job\)/, @logger.messages)
253+
end
254+
255+
def test_enqueue_at_log_when_enqueue_error_is_set
256+
EnqueueErrorJob.disable_test_adapter
257+
258+
EnqueueErrorJob.set(wait: 1.hour).perform_later
259+
assert_match(/Failed enqueuing EnqueueErrorJob to EnqueueError\(default\): ActiveJob::EnqueueError \(There was an error enqueuing the job\)/, @logger.messages)
260+
end
261+
248262
def test_for_tagged_logger_support_is_consistent
249263
set_logger ::Logger.new(nil)
250264
OverriddenLoggingJob.perform_later "Dummy"

0 commit comments

Comments
 (0)