Skip to content

Commit

Permalink
Allow enqueueing into a batch instance
Browse files Browse the repository at this point in the history
* Allows enqueueing a job within a job, as part of the batch
  • Loading branch information
jpcamara committed Sep 24, 2024
1 parent 5ba1c27 commit 59e521a
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions app/models/solid_queue/job_batch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,20 @@ def as_active_job(active_job_klass)
end
end

# Instance-level enqueue
def enqueue(attributes = {})
previous_batch_id = self.class.current_batch_id.presence || nil

transaction do
ActiveSupport::IsolatedExecutionState[:current_batch_id] = id
yield self
end

self
ensure
ActiveSupport::IsolatedExecutionState[:current_batch_id] = previous_batch_id
end

def finished?
finished_at.present?
end
Expand Down

0 comments on commit 59e521a

Please sign in to comment.