Batch background jobs with Sidekiq

Tram Ho

When we want to create multiple background jobs that run in parallel and want to know when all of those jobs are complete, what do we do?

Sidekiq Pro allows me to run a set of background jobs in parallel and then receive a callback right after all jobs have been run. However, Sidekiq Pro is Sidekiq’s paid feature. Thankfully, sidekiq-batch gem has been built based on the Sidekiq Pro API and I can use it for free, and the usage is similar to Sidekiq Pro.


Basic Usage

When the set of all jobs is completed, MyCallBack is executed.

  • complete – when all jobs in the batch have been run at least once, successful or not.
  • success – when all jobs in the batch have been run successfully.
  • death – when an error occurs in the batch

In the above callbacks, params status will have the following options:

Demo Example


As the result above, we see that after the jobs ran in complete parallel, the on_success and on_complete callbacks performed as expected.


Chia sẻ bài viết ngay

Nguồn bài viết : Viblo