Skip to content

Commit 908cee4

Browse files
committed
Fix starting batch in rails 7.1
1 parent d6facee commit 908cee4

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

app/models/solid_queue/batch.rb

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,17 @@ class Batch < Record
2424
def enqueue(&block)
2525
raise "You cannot enqueue a batch that is already finished" if finished?
2626

27-
save! if new_record?
27+
transaction do
28+
save! if new_record?
2829

29-
Batch.wrap_in_batch_context(batch_id) do
30-
block.call(self)
31-
end
30+
Batch.wrap_in_batch_context(batch_id) do
31+
block.call(self)
32+
end
3233

33-
if ActiveRecord.respond_to?(:after_all_transactions_commit)
34-
ActiveRecord.after_all_transactions_commit do
35-
start_batch
34+
if ActiveRecord.respond_to?(:after_all_transactions_commit)
35+
ActiveRecord.after_all_transactions_commit do
36+
start_batch
37+
end
3638
end
3739
end
3840
end

0 commit comments

Comments
 (0)