aboutsummaryrefslogtreecommitdiffstats
path: root/activejob/lib
diff options
context:
space:
mode:
authorSteve S <steves@github.com>2018-08-30 13:04:29 -0400
committerSteve S <steves@github.com>2018-08-30 13:07:37 -0400
commit3bf33d7c2c3ef3b20173d82bf9af6b953ebc5ff2 (patch)
tree9b867e0bfbab1c4aacd6ea4bcb79de940b4d3436 /activejob/lib
parent26dc9bc8ee8639b1ad393f4f3f4fa3e1a397b70e (diff)
downloadrails-3bf33d7c2c3ef3b20173d82bf9af6b953ebc5ff2.tar.gz
rails-3bf33d7c2c3ef3b20173d82bf9af6b953ebc5ff2.tar.bz2
rails-3bf33d7c2c3ef3b20173d82bf9af6b953ebc5ff2.zip
Move ActiveJob retry and discard logging into log subscriber
Diffstat (limited to 'activejob/lib')
-rw-r--r--activejob/lib/active_job/exceptions.rb8
-rw-r--r--activejob/lib/active_job/logging.rb28
2 files changed, 31 insertions, 5 deletions
diff --git a/activejob/lib/active_job/exceptions.rb b/activejob/lib/active_job/exceptions.rb
index 594870c031..9a14c33d80 100644
--- a/activejob/lib/active_job/exceptions.rb
+++ b/activejob/lib/active_job/exceptions.rb
@@ -48,11 +48,11 @@ module ActiveJob
job: self,
adapter: self.class.queue_adapter,
error: error,
+ wait: wait
}
if executions < attempts
ActiveSupport::Notifications.instrument("enqueue_retry.active_job", payload) do
- logger.error "Retrying #{self.class} in #{wait} seconds, due to a #{error.class}. The original exception was #{error.cause.inspect}."
retry_job wait: determine_delay(wait), queue: queue, priority: priority
end
else
@@ -61,7 +61,7 @@ module ActiveJob
yield self, error
end
else
- logger.error "Stopped retrying #{self.class} due to a #{error.class}, which reoccurred on #{executions} attempts. The original exception was #{error.cause.inspect}."
+ ActiveSupport::Notifications.instrument("retry_stopped.active_job", payload)
raise error
end
end
@@ -91,14 +91,12 @@ module ActiveJob
payload = {
job: self,
adapter: self.class.queue_adapter,
- error: error,
+ error: error
}
ActiveSupport::Notifications.instrument("discard.active_job", payload) do
if block_given?
yield self, error
- else
- logger.error "Discarded #{self.class} due to a #{error.class}. The original exception was #{error.cause.inspect}."
end
end
end
diff --git a/activejob/lib/active_job/logging.rb b/activejob/lib/active_job/logging.rb
index 9ffd60ad53..96a3e6bf48 100644
--- a/activejob/lib/active_job/logging.rb
+++ b/activejob/lib/active_job/logging.rb
@@ -88,6 +88,34 @@ module ActiveJob
end
end
+ def enqueue_retry(event)
+ job = event.payload[:job]
+ ex = event.payload[:error]
+ wait = event.payload[:wait]
+
+ error do
+ "Retrying #{job.class} in #{wait} seconds, due to a #{ex.class}. The original exception was #{ex.cause.inspect}."
+ end
+ end
+
+ def retry_stopped(event)
+ job = event.payload[:job]
+ 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}."
+ end
+ end
+
+ def discard(event)
+ job = event.payload[:job]
+ ex = event.payload[:error]
+
+ error do
+ "Discarded #{job.class} due to a #{ex.class}. The original exception was #{ex.cause.inspect}."
+ end
+ end
+
private
def queue_name(event)
event.payload[:adapter].class.name.demodulize.remove("Adapter") + "(#{event.payload[:job].queue_name})"