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

Add section for exception handling #139

Merged

Conversation

chiraggshah
Copy link
Contributor

@chiraggshah chiraggshah commented Jan 29, 2024

@rosa : I have added the documentation as discussed in #120. Let me know your feedback.

@brunoprietog
Copy link
Contributor

Why not use rescue_from instead? As stated in the Active Job guide

@chiraggshah
Copy link
Contributor Author

@brunoprietog : Thanks for the input. I have updated the PR.

@brunoprietog
Copy link
Contributor

Nice! Now it looks much cleaner

class ApplicationMailer < ActionMailer::Base
ActionMailer::MailDeliveryJob.rescue_from(Exception) do |exception|
Rails.error.report(exception)
end
Copy link
Member

Choose a reason for hiding this comment

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

With this suggestion and the above, the job will succeed because the exception will be rescued. I think you don't want this in the majority of cases, you want your job to fail so you can inspect it and retry it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have added the line to raise the exception.

Copy link
Member

@rosa rosa left a comment

Choose a reason for hiding this comment

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

This looks good but I think we should re-raise the exception in both examples or people will have failing jobs succeed without an opportunity to examine or retry them.

@rosa
Copy link
Member

rosa commented Feb 13, 2024

Also... I need to look a bit deeper into this, but I'm not sure using around_perform as it was used before, and rescue_from is fully equivalent. In the first case, we're scoping the block where an exception is captured to the perform method, and in the second case, we can rescue any exception even if it happens outside perform 🤔 I'm not sure if this makes a difference, I'd need to dig deeper into it, it's just that it's not completely obvious to me that these are equivalent.

@chiraggshah
Copy link
Contributor Author

@rosa : Good point. I too will have a look.

@rosa rosa merged commit 7a781de into rails:main Sep 16, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants