docs/Pro-2.0-Upgrade.md
Sidekiq Pro 2.0 allows nested batches for more complex job workflows and provides a new reliable scheduler which uses Lua to guarantee atomicity and much higher performance.
It also removes deprecated APIs, changes the batch data format and how features are activated. Read carefully to ensure your upgrade goes smoothly.
Sidekiq Pro 2.0 requires Sidekiq 3.3.2 or greater. Redis 2.8 is recommended; Redis 2.4 or 2.6 will work but some functionality will not be available.
Note that you CANNOT go back to Pro 1.x once you've created batches with 2.x. The new batches will not process correctly with 1.x.
If you are on a version of Sidekiq Pro <1.5, you should upgrade to the latest 1.x version and run it for a week before upgrading to 2.0.
Batches can now be nested within the jobs method.
This feature enables Sidekiq Pro to handle workflow processing of any size
and complexity!
a = Sidekiq::Batch.new
a.on(:success, SomeCallback)
a.jobs do
SomeWork.perform_async
b = Sidekiq::Batch.new
b.on(:success, MyCallback)
b.jobs do
OtherWork.perform_async
end
end
Parent batch callbacks are not processed until all child batch callbacks have
run successfully. In the example above, MyCallback will always fire
before SomeCallback because b is considered a child of a.
Of course you can dynamically add child batches while a batch job is executing.
def perform(*args)
do_something(args)
if more_work?
# Sidekiq::Worker#batch returns the Batch this job is part of.
batch.jobs do
b = Sidekiq::Batch.new
b.on(:success, MyCallback)
b.jobs do
OtherWork.perform_async
end
end
end
end
More context: [#1485]
The batch data model was overhauled. Batch data should take significantly less space in Redis now. A simple benchmark shows 25% savings but real world savings should be even greater.
There's no data migration required. Sidekiq Pro 2.0 transparently handles both old and new format.
More context: [#2130]
2.0 brings a new reliable scheduler which uses Lua inside Redis so enqueuing scheduled jobs is atomic. Benchmarks show it 50x faster when enqueuing lots of jobs.
Two caveats:
You no longer require anything to use the Reliability features.
Sidekiq.configure_server do |config|
config.reliable_fetch!
config.reliable_scheduler!
end
Sidekiq::Client.reliable_push!
More context: [#2130]
sidekiq/pro/notifications if you want to use the
existing notification schemes. I don't recommend using them as the
newer-style Sidekiq::Batch#on method is simpler and more flexible.attr_accessor :jid to a Batch callback class and Sidekiq
Pro will set it to the jid of the callback job. [#2178]Sidekiq::BatchSet.new.each {|status| p status.bid }
Adam Prescott, Luke van der Hoeven and Jon Hyman all provided valuable feedback during the release process. Thank you guys!