activity_notification icon indicating copy to clipboard operation
activity_notification copied to clipboard

Mailer jobs not cleaned up when a notification is destroyed

Open sina-s opened this issue 6 years ago • 4 comments

I'm using this awesome gem and I have a notifiable model with dependent_notifications: :destroy enabled. The issue is that if the notifiable is created and shortly destroyed before the mailer job is performed, I get a Couldn't find ActivityNotification::Notification with 'id'=xyz error in the background jobs cause the corresponding notification is destroyed. I know this is an edge case, but there is a real case for it, in my case, the notifiable is a "Like" action and if user clicks on Like and UnLike quickly this happens. I also couldn't keep the notifications around after the notifiable is destroyed cause the email template then can't find the Notifiable to generate an email.

sina-s avatar Dec 14 '17 19:12 sina-s

Also googling around a bit for canceling Active Jobs (DelayedJobs in my case) in a callback monkey-patched to ActivityNotification::Notification, it turns out there is no supported API to do that. A better/simpler way would be to let the mailer job execute but do nothing if the notification is destroyed. Not sure that's doable in ActionMailer::DeliveryJob.

sina-s avatar Dec 14 '17 19:12 sina-s

This makes sense. Is it OK to add the option which Mailer will ignore them or just create logs without sending email when Notification record cannot be found?

simukappu avatar Dec 17 '17 09:12 simukappu

Yes, that's ideal

sina-s avatar Dec 17 '17 16:12 sina-s

This seems to still be an issue, is there a workaround?

supairish avatar Apr 28 '22 23:04 supairish