When I faced this problem, I spent 3~4 hours solving it. I’ll summarize it in order not to forget it again.
My original code
User.transaction do user = User.create!(param) UserMailWorker.perform_async(user.id) end
It is a pity that this code sometimes doesn’t work because UserMailWorker is executed before transaction is committed. Thus, there is no user when Worker is executed. This issue is mentioned in Sidekiq.
I have been developing software which enable my colleagues to finish their tasks more effectively. In order to make it, it is necessary to use a library, fabric js. Since there was a problem it took much time to solve, I’ ll introduce it.