I am considering using Sidekiq::Batch
and learning from the following reference: https://github.com/sidekiq/sidekiq/wiki/Batches
I would like to know if the following is possible and what would happen in that case:
In the example below, I schedule a job using perform_in
inside a batch.
The last of MyJob should be executed 5 hours later.
batch = Sidekiq::Batch.new
batch.on(:success, MyCallback)
batch.jobs do
5.times do |index|
MyJob.perform_in((1 * index).hour, args)
end
end
By setting batch.on(:success, MyCallback)
, I can do something after all jobs have completed.
Here, All jobs should be completed in 5 hours and a few minutes.
My questions are:
I appreciate any help as I am not familiar with Sidekiq, thank you in advance.
Yes.
There is batch counter inside Redis that says 5 jobs. As each job finishes, that counter is decremented. On 0, the callback fires.
Not at all. The batch is just data, it does not execute and consumes no resources while in progress, only the jobs and callbacks actually execute.