Bulk adding jobs to a batch - how to combine bulk and batch? #1186
-
I have a potentially large amount of jobs that I want to enqueue and run in a batch. I also read about the bulk enqueuing functionality and thought, I'd combine them: update_batch = GoodJob::Batch.new(on_finish: MyCallbackJob) do
GoodJob::Bulk.enqueue do
[lots_of_things_needing_update].each do |thing|
MyUpdateJob.perform_later(thing: thing, target_version: "1.2.3")
end
end
end
update_batch.description = "Update all things to 1.2.3"
update_batch.save
update_batch.enqueue But somehow, the batch ends up being empty. How do I combine those to enqueue all jobs in a batch and also optimize the query to the database? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
A Batch already Bulk enqueues.
good_job/app/models/good_job/batch.rb Lines 119 to 131 in ae74482 |
Beta Was this translation helpful? Give feedback.
A Batch already Bulk enqueues.
GoodJob::Batch
uses it's own bulking wrapper (aGoodJob::Bulk::Buffer
, which is the lower-level object also used byGoodJob::Bulk
) to capture jobs, so creating a newGoodJob::Bulk
will intercept those jobs and not add them to the batch:good_job/app/models/good_job/batch.rb
Lines 119 to 131 in ae74482