Skip to content

Commit

Permalink
Merge pull request rails#33972 from bogdanvlviv/follow-up-33897
Browse files Browse the repository at this point in the history
Improve `enqueue_retry.active_job` message
  • Loading branch information
rafaelfranca authored Oct 30, 2018
2 parents 3b2ea8b + b0f2f5e commit f487654
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
12 changes: 8 additions & 4 deletions activejob/lib/active_job/logging.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,12 @@ def enqueue_retry(event)
ex = event.payload[:error]
wait = event.payload[:wait]

error do
"Retrying #{job.class} in #{wait.inspect} seconds, due to a #{ex&.class.inspect}. The original exception was #{ex&.cause.inspect}."
info do
if ex
"Retrying #{job.class} in #{wait.to_i} seconds, due to a #{ex.class}."
else
"Retrying #{job.class} in #{wait.to_i} seconds."
end
end
end

Expand All @@ -103,7 +107,7 @@ def retry_stopped(event)
ex = event.payload[:error]

error do
"Stopped retrying #{job.class} due to a #{ex.class}, which reoccurred on #{job.executions} attempts. The original exception was #{ex.cause.inspect}."
"Stopped retrying #{job.class} due to a #{ex.class}, which reoccurred on #{job.executions} attempts."
end
end

Expand All @@ -112,7 +116,7 @@ def discard(event)
ex = event.payload[:error]

error do
"Discarded #{job.class} due to a #{ex.class}. The original exception was #{ex.cause.inspect}."
"Discarded #{job.class} due to a #{ex.class}."
end
end

Expand Down
10 changes: 5 additions & 5 deletions activejob/test/cases/logging_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -169,19 +169,19 @@ def test_job_error_logging
def test_enqueue_retry_logging
perform_enqueued_jobs do
RetryJob.perform_later "DefaultsError", 2
assert_match(/Retrying RetryJob in \d+ seconds, due to a DefaultsError\. The original exception was nil\./, @logger.messages)
assert_match(/Retrying RetryJob in 3 seconds, due to a DefaultsError\./, @logger.messages)
end
end

def test_enqueue_retry_logging_on_retry_job
perform_enqueued_jobs { RescueJob.perform_later "david" }
assert_match(/Retrying RescueJob in nil seconds, due to a nil\. The original exception was nil\./, @logger.messages)
assert_match(/Retrying RescueJob in 0 seconds\./, @logger.messages)
end

def test_retry_stopped_logging
perform_enqueued_jobs do
RetryJob.perform_later "CustomCatchError", 6
assert_match(/Stopped retrying RetryJob due to a CustomCatchError, which reoccurred on \d+ attempts\. The original exception was #<CustomCatchError: CustomCatchError>\./, @logger.messages)
assert_match(/Stopped retrying RetryJob due to a CustomCatchError, which reoccurred on \d+ attempts\./, @logger.messages)
end
end

Expand All @@ -190,15 +190,15 @@ def test_retry_stopped_logging_without_block
begin
RetryJob.perform_later "DefaultsError", 6
rescue DefaultsError
assert_match(/Stopped retrying RetryJob due to a DefaultsError, which reoccurred on \d+ attempts\. The original exception was #<DefaultsError: DefaultsError>\./, @logger.messages)
assert_match(/Stopped retrying RetryJob due to a DefaultsError, which reoccurred on \d+ attempts\./, @logger.messages)
end
end
end

def test_discard_logging
perform_enqueued_jobs do
RetryJob.perform_later "DiscardableError", 2
assert_match(/Discarded RetryJob due to a DiscardableError\. The original exception was nil\./, @logger.messages)
assert_match(/Discarded RetryJob due to a DiscardableError\./, @logger.messages)
end
end
end

0 comments on commit f487654

Please sign in to comment.