Skip to content

Commit c949f44

Browse files
committed
Adding Sidekiq 7 support
1 parent a761df6 commit c949f44

File tree

4 files changed

+13
-8
lines changed

4 files changed

+13
-8
lines changed

lib/sidekiq/batch.rb

+6-5
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ def initialize(existing_bid = nil)
2222
@bidkey = "BID-" + @bid.to_s
2323
@queued_jids = []
2424
@pending_jids = []
25-
@incremental_push = Sidekiq.options.keys.include?(:batch_push_interval)
26-
@batch_push_interval = Sidekiq.options[:batch_push_interval]
25+
sidekiq_config = Sidekiq.const_defined?('MAJOR') && Sidekiq::MAJOR >= 7 ? (Thread.current[:sidekiq_capsule]&.config || Sidekiq.default_configuration) : Sidekiq.options
26+
@incremental_push = sidekiq_config[:batch_push_interval]&.present?
27+
@batch_push_interval = sidekiq_config[:batch_push_interval]
2728
end
2829

2930
def description=(description)
@@ -102,7 +103,7 @@ def jobs
102103

103104
pipeline.expire(@bidkey, BID_EXPIRE_TTL)
104105

105-
pipeline.sadd(@bidkey + "-jids", [@queued_jids])
106+
pipeline.sadd(@bidkey + "-jids", [@queued_jids.flatten])
106107
pipeline.expire(@bidkey + "-jids", BID_EXPIRE_TTL)
107108
end
108109
end
@@ -247,7 +248,7 @@ def enqueue_callbacks(event, bid)
247248
already_processed, _, callbacks, queue, parent_bid, callback_batch = Sidekiq.redis do |r|
248249
r.multi do |pipeline|
249250
pipeline.hget(batch_key, event_name)
250-
pipeline.hset(batch_key, event_name, true)
251+
pipeline.hset(batch_key, event_name, 'true')
251252
pipeline.smembers(callback_key)
252253
pipeline.hget(batch_key, "callback_queue")
253254
pipeline.hget(batch_key, "parent_bid")
@@ -291,7 +292,7 @@ def enqueue_callbacks(event, bid)
291292
else
292293
# Otherwise finalize in sub batch complete callback
293294
cb_batch = self.new
294-
cb_batch.callback_batch = true
295+
cb_batch.callback_batch = 'true'
295296
Sidekiq.logger.debug {"Adding callback batch: #{cb_batch.bid} for batch: #{bid}"}
296297
cb_batch.on(:complete, "Sidekiq::Batch::Callback::Finalize#dispatch", opts)
297298
cb_batch.jobs do

sidekiq-batch.gemspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
1919
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
2020
spec.require_paths = ["lib"]
2121

22-
spec.add_dependency "sidekiq", ">= 3", "<7"
22+
spec.add_dependency "sidekiq", ">= 3", "<8"
2323

2424
spec.add_development_dependency "bundler", "~> 2.1"
2525
spec.add_development_dependency "rake", "~> 13.0"

spec/sidekiq/batch/middleware_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
end
8080

8181
describe Sidekiq::Batch::Middleware do
82-
let(:config) { class_double(Sidekiq) }
82+
let(:config) { Sidekiq.const_defined?('MAJOR') && Sidekiq::MAJOR >= 7 ? double(Sidekiq.default_configuration) : class_double(Sidekiq) }
8383
let(:client_middleware) { double(Sidekiq::Middleware::Chain) }
8484

8585
context 'client' do

spec/spec_helper.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
require 'sidekiq/testing'
2+
Sidekiq::Testing.fake!
3+
14
require "simplecov"
25
SimpleCov.start
36

@@ -6,7 +9,8 @@
69
require 'sidekiq/batch'
710

811
redis_opts = { url: "redis://127.0.0.1:6379/1" }
9-
redis_opts[:driver] = Redis::Connection::Memory if defined?(Redis::Connection::Memory)
12+
# This doesn't work with Sidekiq 7. Is fakeredis even needed?
13+
# redis_opts[:driver] = Redis::Connection::Memory if defined?(Redis::Connection::Memory)
1014

1115
Sidekiq.configure_client do |config|
1216
config.redis = redis_opts

0 commit comments

Comments
 (0)