From 209ec274429714dfc9ec97846658b261162df6ec Mon Sep 17 00:00:00 2001 From: Matt Robinson Date: Sat, 4 Nov 2023 21:58:25 -0400 Subject: [PATCH] fix compabitability with sidekiq < 7 --- lib/sidecloq/locker.rb | 5 +++++ test/test_runner.rb | 2 +- test/test_schedule.rb | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/sidecloq/locker.rb b/lib/sidecloq/locker.rb index cd7357a..cb367ef 100644 --- a/lib/sidecloq/locker.rb +++ b/lib/sidecloq/locker.rb @@ -8,6 +8,11 @@ class Locker def initialize(options = {}) # we keep a connection from the pool by default @redis = options[:redis] || Sidekiq.redis_pool.checkout + # for compatibility with sidekiq < 7, we need to convert the Redis + # instance to a RedisClient instance, which redlock requires + if defined?(Redis) && @redis.instance_of?(Redis) + @redis = RedisClient.new(@redis.connection.except(:location)) + end @key = options[:lock_key] || DEFAULT_LOCK_KEY @ttl = options[:ttl] || 60 @check_interval = options[:check_interval] || 15 diff --git a/test/test_runner.rb b/test/test_runner.rb index 93be6d3..3cb3c5c 100644 --- a/test/test_runner.rb +++ b/test/test_runner.rb @@ -1,4 +1,4 @@ -require 'helper' +require_relative 'helper' class TestRunner < Sidecloq::Test describe 'runner' do diff --git a/test/test_schedule.rb b/test/test_schedule.rb index 42dc72a..c2b7fd3 100644 --- a/test/test_schedule.rb +++ b/test/test_schedule.rb @@ -1,4 +1,4 @@ -require 'helper' +require_relative 'helper' class TestSchedule < Sidecloq::Test describe 'schedule' do