Skip to content

Commit

Permalink
retry_job should publish enqueue_retry.active_job notification
Browse files Browse the repository at this point in the history
Also this commit removes `:wait` from payload of
`retry_stopped.active_job`.

Related to #33751 (comment)
Follow up #33751

/cc @kaspth, @rafaelfranca
  • Loading branch information
bogdanvlviv committed Sep 16, 2018
1 parent fa2001a commit b6b5a7a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
28 changes: 17 additions & 11 deletions activejob/lib/active_job/exceptions.rb
Expand Up @@ -46,18 +46,15 @@ module ClassMethods
# end
def retry_on(*exceptions, wait: 3.seconds, attempts: 5, queue: nil, priority: nil)
rescue_from(*exceptions) do |error|
payload = {
job: self,
adapter: self.class.queue_adapter,
error: error,
wait: wait
}

if executions < attempts
ActiveSupport::Notifications.instrument("enqueue_retry.active_job", payload) do
retry_job wait: determine_delay(wait), queue: queue, priority: priority
end
retry_job wait: determine_delay(wait), queue: queue, priority: priority, error: error
else
payload = {
job: self,
adapter: self.class.queue_adapter,
error: error
}

if block_given?
ActiveSupport::Notifications.instrument("retry_stopped.active_job", payload) do
yield self, error
Expand Down Expand Up @@ -127,7 +124,16 @@ def discard_on(*exceptions)
# end
# end
def retry_job(options = {})
enqueue options
payload = {
job: self,
adapter: self.class.queue_adapter,
error: options[:error],
wait: options[:wait]
}

ActiveSupport::Notifications.instrument("enqueue_retry.active_job", payload) do
enqueue options
end
end

private
Expand Down
2 changes: 1 addition & 1 deletion activejob/lib/active_job/logging.rb
Expand Up @@ -94,7 +94,7 @@ def enqueue_retry(event)
wait = event.payload[:wait]

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

Expand Down
5 changes: 5 additions & 0 deletions activejob/test/cases/logging_test.rb
Expand Up @@ -173,6 +173,11 @@ def test_enqueue_retry_logging
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)
end

def test_retry_stopped_logging
perform_enqueued_jobs do
RetryJob.perform_later "CustomCatchError", 6
Expand Down

0 comments on commit b6b5a7a

Please sign in to comment.