Reputation: 137
I am trying to schedule an email to be sent with a delay after an action is triggered. I'm using Action Mailer with the deliver_later functionality :
UserMailer.email_form(params[:session][:email]).deliver_later(wait: 2.minute)
It works fine locally and on heroku, except if I restart the server/deploy again while an email is scheduled but hasn't been sent. How do I get around this?
Upvotes: 0
Views: 579
Reputation: 7033
I think the problem is: deliver_later
uses ActiveJob (a part/framework of Rails) under the hood to send emails in background. Rails by default comes with an async queue implementation that runs jobs with an in-process thread pool. Jobs will run asynchronously, but any jobs in the queue will be dropped upon restart or process crashes, because they are only in RAM (memory), but not in a persistent backend (DB, Redis).
You should switch to a different adapter (Sidekiq, Resque, Delayed Job, ...) if you want your jobs to be persisted.
You can find more details here.
Upvotes: 1