Skip to content
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

Extract "execute" method to reduce "perform" method complexity #138

Merged
merged 1 commit into from
Sep 16, 2020

Conversation

morgoth
Copy link
Collaborator

@morgoth morgoth commented Sep 16, 2020

While looking at a way to implement #136 I found perform method quite complex and was trying to simplify it a bit.

Feel free to close it if you prefer to have it in one method.


retry_or_discard_error = GoodJob::CurrentExecution.error_on_retry ||
GoodJob::CurrentExecution.error_on_discard

error = nil
if rescued_error
error = rescued_error
elsif result.is_a?(Exception)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know why/when the result can be an exception? I find it quite surprising.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question! Apologies if this turns into story time.

Briefly: when using ActiveJob.rescue_from (or retry_on / discard_on which are implemented with rescue_from), ActiveJob will return the exception that is caught/handled.

Storytime...

I'm not sure whether the above behavior is intentional or merely a coincidence.

The behavior is unreliable though. I discovered in production that Sentry's instrumentation interrupts that behavior: https://github.com/getsentry/raven-ruby/blob/a5f101a9c7776168df1c0e2aac13d46b70bbb24e/lib/raven/integrations/rails/active_job.rb#L21-L31

...you'll notice that Sentry will call rescue_with_handler but does not return the result. I just checked it off my todo list by submitting a PR (thanks for the inspiration 🎉 ): getsentry/sentry-ruby#1027 ...but I have to assume that other gems may also interrupt this behavior too. This is explored in #72.

Copy link
Owner

@bensheldon bensheldon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a great refactor.

A weakly held stylistic thought is that result, rescued_error = execute does visually understate THIS IS WHERE THE WORK HAPPENS and I could see it being overlooked by someone visiting this file with fresh eyes.

...but that's not really actionable feedback. I will merge this and keep it in mind 🙌

@bensheldon bensheldon merged commit 912aa61 into bensheldon:main Sep 16, 2020
@bensheldon bensheldon added the refactor Code changes that do not introduce new features label Sep 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactor Code changes that do not introduce new features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants