Actual Result:
We are getting failed mailer jobs showing up on sidekiq web UI ( using sidekiq-failures gem ) which get successfully retried after about a minute.
Failure Error:
ActiveRecord::RecordNotFound: Couldn't find User with 'id'=234
Expected:
We expect the sidekiq worker to succeed right away and not fail and later get (albeit successfully) retried.
Setup: Heroku Cedar-14, Rails 4.2, Puma 2.11.2, Sidekiq 3.3.4, Sidekiq-failures 0.4.4
config/initializers/sidekiq.rb:
Sidekiq.configure_server do |config|
database_url = ENV['DATABASE_URL']
if database_url
ENV['DATABASE_URL'] = "#{database_url}?pool=15"
ActiveRecord::Base.establish_connection
end
end
config/puma.rb:
workers Integer(ENV['WEB_CONCURRENCY'] || 2)
threads_count = Integer(ENV['MAX_THREADS'] || 5)
threads threads_count, threads_count
preload_app!
rackup DefaultRackup
port ENV['PORT'] || 3000
environment ENV['RACK_ENV'] || 'development'
on_worker_boot do
ActiveRecord::Base.establish_connection
end
config/sidekiq.yml
---
:concurrency: 25
:queues:
- default
- mailers
- [low, 1]
- [med, 2]
- [high, 3]
The email is triggered from a service run in the controller action:
app/services/user_events.rb
@user = User.find(234)
UserMailer.send_email(@user.id).deliver_later
app/mailers/user_mailer.rb
def send_email(user_id)
@user = User.find(user_id)
# mandrill_headers
headers['X-MC-Track'] = "opens, clicks_all"
headers['X-MC-Tags'] = ['user-event']
mail(to: @user.email, subject: "Hi", css: ["email"])
end