I'm working on a Rails application that sends emails in the background using Sidekiq and Mandrill. In my application I have 2 queues, one for user interactions with my service (irrelevant) and the second is a mailer queue. The mailer queue is used by 2 mailers: One for managing the user profile and the other one is for interactions with our service (irrelevant).
Today I noticed that users are not getting emails for a few days already except the confirmation email that is sent by Devise.
The other queue is working flawlessly and doesn't have any problems. (So maybe Sidekiq configuration is not the problem).
For example lets take the UserMailer that notifies the user of a successful profile update:
user_mailer.rb
def update_user(user)
@user = user
mail(:to => user.email)
end
user_profile_controller.rb
def update_resource(user)
user.save
UserMailer.update_user(user).deliver_later(wait: 1.minute)
end
When I tried testing this function with deliver_now instead of deliver_later it worked and the mail was sent (So the connection with Mandrill is working). When I test this function as it is, the job is being added to the mailer queue. When it's time to send the email it just disappears from the queue without sending the email and without leaving any exceptions in the logs.
I can see it appear in the Sidekiq Web UI and then disappear.
I guess the confirmation email is the only one being sent because it isn't delayed, but I don't know why this is happenning.
Everything is working great on my staging environment. The difference is that it's working with mailtrap and doesn't have as much jobs as the production.
Some code that might be relevant:
production.rb
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:user_name => 'xxx',
:password => Rails.application.secrets.smtp_password,
:address => 'smtp.mandrillapp.com',
:domain => config.app_domain,
:port => 'xxx',
:authentication => :login
}
...
config.action_mailer.default_url_options = { :host => config.app_domain, :protocol => 'https' }
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = false
application.rb
config.active_job.queue_adapter = :sidekiq
Walked through these links without any solution:
http://guides.rubyonrails.org/active_job_basics.html http://api.rubyonrails.org/classes/ActionMailer/Base.html
Haven't found any other links relevant to my issue.
I'm suspecting it has something to do with lack of memory on the server. When I increased the memory on the server and the max_connections parameter on postgres, all the emails on that queue that were supposed to be sent, were delivered immediately