Is job creation done in the same transaction as everything else, and can be rolled back? #908
-
(This might be a very basic question and I'm missing something in the docs - I thought this was part of the main premise of goodjob, but couldn't find the answer in the readme.) does job enqueueing happen in the same transaction as everything else, and will be rolled back? example # my_model.rb
transaction do
admins.each do |admin|
UserMailer.with(user: admin).notify_about_thing.deliver_later
end
user1.update!(foo: 'bar')
end if |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Yes, though there might be edge cases; for example, I'm not sure about the intricacies of The simplest case should work: expect do
ApplicationRecord.transaction do
TestJob.perform_later
raise ActiveRecord::Rollback
end
end.not_to change(GoodJob::Job, :count) |
Beta Was this translation helpful? Give feedback.
Yes, though there might be edge cases; for example, I'm not sure about the intricacies of
require_new
andjoinable
and Active Record's built-in transactions.The simplest case should work: