ActiveRecord uses #transactionto create a started block and either rolls back or commits a transaction. I believe this will help your problem. Essentially (the intended task is the ActiveRecord class):
Task.transaction do
new_task = Task.create(...)
end
BackgroundQueue.enqueue(new_task)
You can also go directly to #connectionunder:
Task.connection.commit_db_transaction
This is a bit low level, and you should be pretty sure how the code is used. #after_commitis the best answer, even if it requires a bit of code conversion to work. If this does not work for sure, then these two approaches should help.
source
share