Skip to content

Commit 69a8899

Browse files
committed
Allow enqueueing into a batch instance
* Allows enqueueing a job within a job, as part of the batch
1 parent 0df6653 commit 69a8899

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

app/models/solid_queue/job_batch.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,20 @@ def as_active_job(active_job_klass)
6969
end
7070
end
7171

72+
# Instance-level enqueue
73+
def enqueue(attributes = {})
74+
previous_batch_id = self.class.current_batch_id.presence || nil
75+
76+
transaction do
77+
ActiveSupport::IsolatedExecutionState[:current_batch_id] = id
78+
yield self
79+
end
80+
81+
self
82+
ensure
83+
ActiveSupport::IsolatedExecutionState[:current_batch_id] = previous_batch_id
84+
end
85+
7286
def finished?
7387
finished_at.present?
7488
end

0 commit comments

Comments
 (0)