英文:
Sidekiq Batch - Scheduling jobs with perform_in and waiting for completion with callbacks
问题
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:
- In this case, will the callback fire correctly after all jobs are completed in 5 hours and a few minutes (all job completed)?
- In that case, where is the batch waiting and how can the batch know the all job has been completed?
- Are there any negative effects if there are many batches waiting for a long time like this?
I appreciate any help as I am not familiar with Sidekiq, thank you in advance.
英文:
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:
- In this case, will the callback fire correctly after all jobs are completed in 5 hours and a few minutes (all job completed)?
- In that case, where is the batch waiting and how can the batch know the all job has been completed?
- Are there any negative effects if there are many batches waiting for a long time like this?
I appreciate any help as I am not familiar with Sidekiq, thank you in advance.
答案1
得分: 1
- 在这种情况下,所有工作在5小时零几分钟后都完成后,回调会正确触发吗(所有工作都完成了)?
是的。
- 在那种情况下,批处理在哪里等待,批处理如何知道所有工作已完成?
在Redis中有一个批次计数器,表示有5个工作。每个工作完成时,该计数器会递减。当计数器为0时,回调触发。
- 如果有许多批次长时间等待会有什么负面影响吗?
完全没有。批处理只是数据,不会在进行中执行,不会消耗任何资源,只有工作和回调实际执行。
英文:
- In this case, will the callback fire correctly after all jobs are completed in 5 hours and a few minutes (all job completed)?
Yes.
- In that case, where is the batch waiting and how can the batch know the all job has been completed?
There is batch counter inside Redis that says 5 jobs. As each job finishes, that counter is decremented. On 0, the callback fires.
- Are there any negative effects if there are many batches waiting for a long time like this?
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论