Here's a situation I am facing. It's very specific to my app, but I'm pretty sure has a root cause in devise-async.
I sometimes remind users who haven't confirmed their email addresses to do so. It goes something like this (some things renamed/simplified):
class User
def remind
self.email_confirmation_reminder_count += 1
send_confirmation_instructions
save!
end
end
then in the email template...
- if @user.email_confirmation_reminder_count > 0
%h6 Complete your account registration.
- else
%h6 Welcome!
Problem: Sometimes when sending the confirmation instructions in this way, @user.email_confirmation_reminder_count is 0, even though it is incremented in User#remind. Inspecting the object at the console after the email has been sent, the incrementing was indeed successful as expected. So, for some reason the User object that was accessed within the template has the value set to 0, but persisting the incremented value within User#remind was successful.
And as a reminder, this problem only happens sometimes.
A Pretty Good Theory
I've actually seen a similar phenomenon before, and I thought it might be the case here too. If it is the case here, then this is what happens:
User.email_confirmation_reminder_count is incremented on the in-memory object
send_confirmation_instructions creates the background job. The background job is started and finishes before step 3...
- The
User object, with email_confirmation_reminder_count incremented, is persisted to the DB.
But That Theory Doesn't Hold With devise-async
As you may know, devise-async specifically goes to great lengths to avoid such a situation: https://github.com/mhfs/devise-async/blob/master/lib/devise/async/model.rb
Beginnings of Other Theories
Help Me
If anyone has any ideas or suggestions for what to investigate, it would be much appreciated!
Hopefully when I solve this I can contribute some documentation that will help others!
Here's a situation I am facing. It's very specific to my app, but I'm pretty sure has a root cause in devise-async.
I sometimes remind users who haven't confirmed their email addresses to do so. It goes something like this (some things renamed/simplified):
then in the email template...
Problem: Sometimes when sending the confirmation instructions in this way,
@user.email_confirmation_reminder_countis0, even though it is incremented inUser#remind. Inspecting the object at the console after the email has been sent, the incrementing was indeed successful as expected. So, for some reason theUserobject that was accessed within the template has the value set to0, but persisting the incremented value withinUser#remindwas successful.And as a reminder, this problem only happens sometimes.
A Pretty Good Theory
I've actually seen a similar phenomenon before, and I thought it might be the case here too. If it is the case here, then this is what happens:
User.email_confirmation_reminder_countis incremented on the in-memory objectsend_confirmation_instructionscreates the background job. The background job is started and finishes before step 3...Userobject, withemail_confirmation_reminder_countincremented, is persisted to the DB.But That Theory Doesn't Hold With devise-async
As you may know, devise-async specifically goes to great lengths to avoid such a situation: https://github.com/mhfs/devise-async/blob/master/lib/devise/async/model.rb
Beginnings of Other Theories
email_confirmation_reminder_count, theUserobject is not consideredchanged?by devise-async https://github.com/mhfs/devise-async/blob/master/lib/devise/async/model.rb#L38 - but this seems basically impossibleUserobject is reloaded... somewhere... in devise, devise-async, or elsewhereHelp Me
If anyone has any ideas or suggestions for what to investigate, it would be much appreciated!
Hopefully when I solve this I can contribute some documentation that will help others!