Skip to content
This repository has been archived by the owner on Jan 24, 2025. It is now read-only.

Commit

Permalink
Add Use Batches guideline
Browse files Browse the repository at this point in the history
Filipp Pirozhkov committed Sep 14, 2019

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 4ff5a31 commit a4039b0
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
@@ -496,6 +496,49 @@ Measure the exact footprint for each job with its arguments.

At some scale, https://github.com/mperham/sidekiq/wiki/Build-vs-Buy[it pays out to use commercial features].

Some commercial features are available as third-party add-ons.
However, their reliability is in most cases questionable.

[#use-batches]
=== Use Batches

Group jobs related to one task using https://github.com/mperham/sidekiq/wiki/Batches[Sidekiq Batches].
Batch's `jobs` method is atomic, i.e., all the jobs are scheduled together, in an all-or-nothing fashion.

[source,ruby]
----
# bad
class BackfillMissingDataJob < ApplicationJob
def self.run_batch
Model.where(attribute: nil).find_each do |model|
perform_later(model)
end
end
def perform(model)
# do the job
end
end
# good
class BackfillMissingDataJob < ApplicationJob
def self.run_batch
batch = Sidekiq::Batch.new
batch.description = 'Backfill missing data'
batch.on(:success, BackfillComplete, to: SysAdmin.email)
batch.jobs do
Model.where(attribute: nil).find_each do |model|
perform_later(model)
end
end
end
def perform(model)
# do the job
end
end
----

[#self-scheduling-jobs]
=== Self-scheduling Jobs

0 comments on commit a4039b0

Please sign in to comment.