-
Notifications
You must be signed in to change notification settings - Fork 22k
Add hooks to ActiveJob around retries and discards #33751
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,14 +44,24 @@ 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 | ||
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 | ||
ActiveSupport::Notifications.instrument("enqueue_retry.active_job", payload) do | ||
retry_job wait: determine_delay(wait), queue: queue, priority: priority | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That is a good question. My thought about this was that if you do the retry manually you don't need to be notified given you know you did the retry. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure. I just think from a UX perspective it seems weird that calling There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we move |
||
end | ||
else | ||
if block_given? | ||
yield self, error | ||
ActiveSupport::Notifications.instrument("retry_stopped.active_job", payload) do | ||
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 | ||
|
@@ -78,10 +88,16 @@ def retry_on(*exceptions, wait: 3.seconds, attempts: 5, queue: nil, priority: ni | |
# end | ||
def discard_on(*exceptions) | ||
rescue_from(*exceptions) do |error| | ||
if block_given? | ||
yield self, error | ||
else | ||
logger.error "Discarded #{self.class} due to a #{error.class}. The original exception was #{error.cause.inspect}." | ||
payload = { | ||
job: self, | ||
adapter: self.class.queue_adapter, | ||
error: error | ||
} | ||
|
||
ActiveSupport::Notifications.instrument("discard.active_job", payload) do | ||
if block_given? | ||
yield self, error | ||
end | ||
end | ||
end | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add
:wait
to "enqueue_retry.active_job" table inguides/source/active_support_instrumentation.md
?