2015-01-11 01:47:42 -05:00
|
|
|
# Upgrading to Sidekiq Pro 2.0
|
|
|
|
|
2015-01-29 14:39:41 -05:00
|
|
|
Sidekiq Pro 2.0 allows nested batches for more complex job workflows
|
2015-02-05 15:24:52 -05:00
|
|
|
and provides a new reliable scheduler which uses Lua to guarantee
|
|
|
|
atomicity and much higher performance.
|
2015-01-29 14:39:41 -05:00
|
|
|
|
2015-01-15 17:25:00 -05:00
|
|
|
It also removes deprecated APIs, changes the batch data format and
|
2015-01-11 01:54:42 -05:00
|
|
|
how features are activated. Read carefully to ensure your upgrade goes
|
|
|
|
smoothly.
|
2015-01-11 01:47:42 -05:00
|
|
|
|
2015-02-05 15:24:52 -05:00
|
|
|
Sidekiq Pro 2.0 requires Sidekiq 3.3.2 or greater. Redis 2.8 is
|
2015-01-29 14:39:41 -05:00
|
|
|
recommended; Redis 2.4 or 2.6 will work but some functionality will not be
|
|
|
|
available.
|
|
|
|
|
2015-01-27 13:09:51 -05:00
|
|
|
**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.**
|
|
|
|
|
2015-02-05 16:28:27 -05:00
|
|
|
**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.**
|
|
|
|
|
2015-01-15 17:25:00 -05:00
|
|
|
## Nested Batches
|
|
|
|
|
2015-01-21 16:12:33 -05:00
|
|
|
Batches can now be nested within the `jobs` method.
|
|
|
|
This feature enables Sidekiq Pro to handle workflow processing of any size
|
|
|
|
and complexity!
|
2015-01-15 17:25:00 -05:00
|
|
|
|
|
|
|
```ruby
|
|
|
|
a = Sidekiq::Batch.new
|
|
|
|
a.on(:success, SomeCallback)
|
|
|
|
a.jobs do
|
|
|
|
SomeWork.perform_async
|
2015-01-20 17:50:05 -05:00
|
|
|
|
2015-01-15 17:25:00 -05:00
|
|
|
b = Sidekiq::Batch.new
|
|
|
|
b.on(:success, MyCallback)
|
|
|
|
b.jobs do
|
|
|
|
OtherWork.perform_async
|
|
|
|
end
|
|
|
|
end
|
|
|
|
```
|
|
|
|
|
2015-03-02 17:45:05 -05:00
|
|
|
Parent batch callbacks are not processed until all child batch callbacks have
|
2015-01-21 15:51:27 -05:00
|
|
|
run successfully. In the example above, `MyCallback` will always fire
|
|
|
|
before `SomeCallback` because `b` is considered a child of `a`.
|
2015-01-15 17:25:00 -05:00
|
|
|
|
2015-01-21 16:12:33 -05:00
|
|
|
Of course you can dynamically add child batches while a batch job is executing.
|
|
|
|
|
|
|
|
```ruby
|
|
|
|
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
|
|
|
|
```
|
|
|
|
|
2015-02-06 00:45:44 -05:00
|
|
|
More context: [#1485]
|
|
|
|
|
2015-01-15 17:25:00 -05:00
|
|
|
## Batch Data
|
2015-01-11 01:47:42 -05:00
|
|
|
|
2015-01-11 01:48:12 -05:00
|
|
|
The batch data model was overhauled. Batch data should take
|
|
|
|
significantly less space in Redis now. A simple benchmark shows 25%
|
2015-01-11 01:54:42 -05:00
|
|
|
savings but real world savings should be even greater.
|
2015-01-11 01:48:12 -05:00
|
|
|
|
2015-01-11 01:47:42 -05:00
|
|
|
* Batch 2.x BIDs are 14 character URL-safe Base64-encoded strings, e.g.
|
2015-01-11 01:48:12 -05:00
|
|
|
"vTF1-9QvLPnREQ". Batch 1.x BIDs were 16 character hex-encoded
|
|
|
|
strings, e.g. "4a3fc67d30370edf".
|
|
|
|
* In 1.x, batch data was not removed until it naturally expired in Redis.
|
|
|
|
In 2.x, all data for a batch is removed from Redis once the batch has
|
|
|
|
run any success callbacks.
|
2015-01-11 01:47:42 -05:00
|
|
|
* Because of the former point, batch expiry is no longer a concern.
|
|
|
|
Batch expiry is hardcoded to 30 days and is no longer user-tunable.
|
2015-01-11 01:48:12 -05:00
|
|
|
* Failed batch jobs no longer automatically store any associated
|
2015-01-15 17:25:00 -05:00
|
|
|
backtrace in Redis.
|
|
|
|
|
2015-01-20 17:50:05 -05:00
|
|
|
**There's no data migration required. Sidekiq Pro 2.0 transparently handles
|
2015-01-15 17:25:00 -05:00
|
|
|
both old and new format.**
|
2015-01-11 01:47:42 -05:00
|
|
|
|
2015-02-06 00:45:44 -05:00
|
|
|
More context: [#2130]
|
|
|
|
|
2015-01-11 01:47:42 -05:00
|
|
|
## Reliability
|
|
|
|
|
2015-02-03 17:24:17 -05:00
|
|
|
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
|
2015-02-18 13:54:49 -05:00
|
|
|
lots of jobs.
|
|
|
|
|
|
|
|
**Two caveats**:
|
|
|
|
- Client-side middleware is not executed
|
|
|
|
for each job when enqueued with the reliable scheduler. No Sidekiq or
|
|
|
|
Sidekiq Pro functionality is affected by this change but some 3rd party
|
|
|
|
plugins might be.
|
|
|
|
- The Lua script used inside the reliable scheduler is not safe for use
|
2015-07-02 14:15:20 -04:00
|
|
|
with Redis Cluster or other multi-master Redis solutions.
|
|
|
|
It is safe to use with Redis Sentinel or a typical master/slave replication setup.
|
2015-02-03 17:24:17 -05:00
|
|
|
|
|
|
|
**You no longer require anything to use the Reliability features.**
|
2015-01-21 15:51:27 -05:00
|
|
|
|
2015-02-03 17:24:17 -05:00
|
|
|
* Activate reliable fetch and/or the new reliable scheduler:
|
2015-01-11 01:47:42 -05:00
|
|
|
```ruby
|
|
|
|
Sidekiq.configure_server do |config|
|
|
|
|
config.reliable_fetch!
|
2015-01-29 14:39:41 -05:00
|
|
|
config.reliable_scheduler!
|
2015-01-11 01:47:42 -05:00
|
|
|
end
|
2015-01-11 01:54:42 -05:00
|
|
|
```
|
2015-01-21 15:51:27 -05:00
|
|
|
* Activate reliable push:
|
2015-01-11 01:47:42 -05:00
|
|
|
```ruby
|
|
|
|
Sidekiq::Client.reliable_push!
|
|
|
|
```
|
2015-01-15 17:25:00 -05:00
|
|
|
|
2015-02-06 00:45:44 -05:00
|
|
|
More context: [#2130]
|
|
|
|
|
2015-01-15 17:25:00 -05:00
|
|
|
## Other Changes
|
|
|
|
|
2015-01-29 14:39:41 -05:00
|
|
|
* You must require `sidekiq/pro/notifications` if you want to use the
|
2015-01-15 17:25:00 -05:00
|
|
|
existing notification schemes. I don't recommend using them as the
|
2015-01-20 17:50:05 -05:00
|
|
|
newer-style `Sidekiq::Batch#on` method is simpler and more flexible.
|
2015-01-21 15:51:27 -05:00
|
|
|
* Several classes have been renamed. Generally these classes are ones
|
|
|
|
you should not need to require/use in your own code, e.g. the Batch
|
|
|
|
middleware.
|
2015-02-06 00:45:44 -05:00
|
|
|
* You can add `attr_accessor :jid` to a Batch callback class and Sidekiq
|
|
|
|
Pro will set it to the jid of the callback job. [#2178]
|
2015-02-17 17:37:21 -05:00
|
|
|
* There's now an official API to iterate all known Batches [#2191]
|
|
|
|
```ruby
|
|
|
|
Sidekiq::BatchSet.new.each {|status| p status.bid }
|
|
|
|
```
|
2015-02-06 00:45:44 -05:00
|
|
|
* The Web UI now shows the Sidekiq Pro version in the footer. [#1991]
|
2015-01-26 16:34:20 -05:00
|
|
|
|
|
|
|
## Thanks
|
|
|
|
|
|
|
|
Adam Prescott, Luke van der Hoeven and Jon Hyman all provided valuable
|
|
|
|
feedback during the release process. Thank you guys!
|