noticed: Handle deserialization error for deliver_by email when record destroyed
Probably would be nice to have an explanation in the readme like this:
class NotificationMailer < ApplicationMailer
rescue_from(ActiveJob::DeserializationError) do |e|
Rails.logger.info("Skipping notification due to #{e.message}")
end
def some_notification
# ... params[:some_record] that can be destroyed, will raise ActiveJob::DeserializationError, so we catch it.
end
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 15 (9 by maintainers)
PR opened! #189
Good to know, thanks @tbcooney! I’ll open a PR with a new section to the README.
Add it as a best practise!
The Rails guides explain that
after_commitis the only callback that is triggered once the database transaction is committed. I have a propensity to not read and these errors are frustrating to track down. But, it’s well documented online that without anafter_commitcallback, you may see strange errors in Sidekiq to the tune ofCannot find ActionText::Attachment with ID=12345.I’ve found this to be a best practise when using Rails callbacks (just to be clear, the best practise being the preference of
after_committoafter_create).We enqueued the notifications via a callback on the model.
For example,
We probably should’ve been using
after_create_commitrather than aafter_createcallback to ensure that transaction for both the Note and the ActionText::RichText were completed.