Rails - Delayed Job - Sending an email for a deleted object
I have an issue where I'm using DelayedJob to send out emails, using the .delay method call for deleted objects. I have an Observer that checks for after_destroy and it kicks off a delayed email, but I'm getting
Delayed::DeserializationError
I know I'm getting this error cause the Record is not found but is there a way to bypass this to just开发者_Go百科 send the email with the information in the delayed_jobs table and not look up the object in the database? Any help would be appreciated. Thanks!
All you need to do is wrap up the parts of your object in another object (before you delete it) and then call .delay
on that:
notifier = WhatEver.new(self)
notifier.delay.send_email
Wrap something like that in a before_destroy
callback on the thing you're destroying. The WhatEver
class just pulls the relevant bits of information out of the object, stores those bits in instance variables, and then WhatEver#send_email
builds and sends the email based on the information it extracted.
Doing things this way breaks the connection between the email and the (soon to be) dead object and should avoid the DeserializationError
.
精彩评论