“Cannot find ModelName with ID=12345”
Sidekiq is so fast that it is quite easy to get transactional race conditions where a job will try to access a database record that has not committed yet. The clean solution is to use
class User < ActiveRecord::Base after_commit :greet, :on => :create def greet UserMailer.delay.send_welcome_email(self.id) end end
after_commit will not be invoked in your tests if you have
use_transactional_fixturesenabled, but test_after_commit has been written to help out in this case.
If you aren’t using ActiveRecord models, use a scheduled perform to run after you can be sure the transaction has committed:
MyWorker.perform_in(5.seconds, 1, 2, 3)
Either way, Sidekiq’s retry mechanism’s got your back. The first time might fail with RecordNotFound but the retry will succeed.
Copied from ; as notes