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

Add hooks to ActiveJob around retries and discards #33751

Merged
merged 2 commits into from Aug 30, 2018

Conversation

@steves
Contributor

steves commented Aug 29, 2018

Summary

This started life as #33740 but it was decided that this would be the better implementation for now. The goal here is to add a few additional hooks to ActiveJob that can be used to perform logging and monitoring around retries and discards. Right now the only two options to do so are to implement some version of your own retry_on and discard_on or do the monitoring on each individual job.

Other Information

Because the notification is sent off after the block is executed I only include the retry stopped case where a block was provided. Since the other case just re-raises the exception I figured whatever exception logging you have in place should handle that case. I'm open to suggestions to implement that differently though.

@rails-bot

This comment has been minimized.

Show comment
Hide comment
@rails-bot

rails-bot Aug 29, 2018

Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @schneems (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

This repository is being automatically checked for code quality issues using Code Climate. You can see results for this analysis in the PR status below. Newly introduced issues should be fixed before a Pull Request is considered ready to review.

Please see the contribution instructions for more information.

rails-bot commented Aug 29, 2018

Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @schneems (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

This repository is being automatically checked for code quality issues using Code Climate. You can see results for this analysis in the PR status below. Newly introduced issues should be fixed before a Pull Request is considered ready to review.

Please see the contribution instructions for more information.

@eileencodes eileencodes added this to the 6.0.0 milestone Aug 30, 2018

@steves

This comment has been minimized.

Show comment
Hide comment
@steves

steves Aug 30, 2018

Contributor

@rafaelfranca @eileencodes Updated with your feedback in mind. I also decided to move the log calls inside retry_on and discard_on into the log subscriber so that it would be consistent with the existing perform and enqueue logging. I also added the appropriate tests to logging_tests.rb for these use cases.

Contributor

steves commented Aug 30, 2018

@rafaelfranca @eileencodes Updated with your feedback in mind. I also decided to move the log calls inside retry_on and discard_on into the log subscriber so that it would be consistent with the existing perform and enqueue logging. I also added the appropriate tests to logging_tests.rb for these use cases.

@rafaelfranca rafaelfranca merged commit 5bbaae0 into rails:master Aug 30, 2018

2 checks passed

codeclimate All good!
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
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

This comment has been minimized.

@kaspth

kaspth Aug 30, 2018

Member

Should retry_job publish this notification?

@kaspth

kaspth Aug 30, 2018

Member

Should retry_job publish this notification?

This comment has been minimized.

@rafaelfranca

rafaelfranca Aug 30, 2018

Member

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.

@rafaelfranca

rafaelfranca Aug 30, 2018

Member

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.

This comment has been minimized.

@kaspth

kaspth Aug 30, 2018

Member

Sure. I just think from a UX perspective it seems weird that calling retry_job doesn't publish the enqueue_retry notification.

@kaspth

kaspth Aug 30, 2018

Member

Sure. I just think from a UX perspective it seems weird that calling retry_job doesn't publish the enqueue_retry notification.

This comment has been minimized.

@bogdanvlviv

bogdanvlviv Sep 3, 2018

Contributor

Should we move ActiveSupport::Notifications.instrument("enqueue_retry.active_job", payload) to retry_job?

@bogdanvlviv

bogdanvlviv Sep 3, 2018

Contributor

Should we move ActiveSupport::Notifications.instrument("enqueue_retry.active_job", payload) to retry_job?

job: self,
adapter: self.class.queue_adapter,
error: error,
wait: wait

This comment has been minimized.

@bogdanvlviv

bogdanvlviv Sep 3, 2018

Contributor

Should we add :wait to "enqueue_retry.active_job" table in guides/source/active_support_instrumentation.md?

@bogdanvlviv

bogdanvlviv Sep 3, 2018

Contributor

Should we add :wait to "enqueue_retry.active_job" table in guides/source/active_support_instrumentation.md?

bogdanvlviv added a commit to bogdanvlviv/rails that referenced this pull request Sep 16, 2018

Payload of `enqueue_retry.active_job` includes `:wait`
Add mention about it to the "Active Support Instrumentation" guide

Related to rails#33751 (comment)
Follow up #33751

bogdanvlviv added a commit to bogdanvlviv/rails that referenced this pull request Sep 16, 2018

`retry_job` should publish `enqueue_retry.active_job` notification
Also this commit removes `:wait` from payload of
`retry_stopped.active_job`.

Related to rails#33751 (comment)
Follow up #33751

/cc @kaspth, @rafaelfranca

@bogdanvlviv bogdanvlviv referenced this pull request Sep 16, 2018

Merged

Follow up #33751 #33897

rafaelfranca added a commit that referenced this pull request Sep 18, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment