I have a rails 4.2.3 app running on an ubuntu server with nginx, postgres, and puma and I'm using Capistrano for deployments.
Users of my app can send bulk emails out using several different email templates I provide and making use of the Delayed_Job gem. Recently, I updated two of the email templates and I've found that occasionally (maybe 20 times out of 500) an old version of the email template is sent out rather than the current version. I've combed through my application code and I'm satisfied that the old version of the template no longer exists anywhere in the application.
What's more, users are able to edit the template by providing their own body text, and, when an old version of an email template is sent, it is sent with the correct body text that the user specifies. It's as if there's an old version of my app running on the server that occasionally commandeers the sending of an email.
Is it possible that somehow as I update my deployment using Capistrano, the old application process remains running and sometimes starts working off the delayed_job queue? Capistrano only keeps the 5 most recent versions of my application though, and none of them have the old email template that is being used. So if this was the case the old application process would need to be entirely kept in memory--so this doesn't seem possible.
Anyone have any ideas I can pursue? I'm stumped as to what could be causing this (or how this problem is even possible). Thanks so much for any help!
(PS: emails make use of the premailer gem, though I don't see how that could be involved)
The answer to this question was yes, "Is it possible that somehow as I update my deployment using Capistrano, the old application process remains running and sometimes starts working off the delayed_job queue?"
I was very surprised to find that, when you start a delayed job
process, it serializes / saves into memory everything it needs to complete its tasks. A.K.A it saves / creates a new instance of the whole application, for practical purposes. Old delayed job processes weren't being properly killed when I pushed changes to my app, so I had something like 20 delayed job processes going at once. For the most part, the most recent delayed job process would take over the queue. If it was busy, however, old processes would butt in and start working off jobs using an old version of my application.
To fix the problem I had to kill off the old delayed job processes and then update my Capistrano code to make sure it wouldn't happen again.
Big thanks to @Dharam for leading me down the correct path (it's taken me a while to post this answer)