Rails 7.2 released a feature that enqueues active jobs by default after all transactions are committed and they deprecated the global setting
I am unable to get this behavior to work:
ActiveRecord::Base.transaction do
user = User.find(1)
user.first_name = "Race Condition #{SecureRandom.uuid}"
user.save!
ActiveRecord.after_all_transactions_commit do
LotsOfWork.perform_later(user.id)
end
LotsOfWork.perform_later(user.id)
end
The code in the after_all_transactions_commit
block does execute outside of the transaction but the perform_later
inside the transaction does not wait until the transaction is over. I have even tried to manually set the option as mentioned in the docs:
class LotsOfWork < ApplicationJob
self.enqueue_after_transaction_commit = :always
sidekiq_options backtrace: true, retry: 0
def perform(user_id)
user = User.find(patient_id)
user.do_lots_of_work
end
end
No luck! I'm on the latest version of Sidekiq 7.3.8
and ActiveJob 7.2.2.1
. Am I misunderstanding the feature or is it possible Sidekiq or Rails has a bug?