Skip to content

Commit c5139e5

Browse files
committed
feat(digest): allow modern algorithm
1 parent bdca185 commit c5139e5

File tree

22 files changed

+142
-44
lines changed

22 files changed

+142
-44
lines changed

.github/workflows/rspec.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ jobs:
6363
- sidekiq_7.0
6464
- sidekiq_7.1
6565
- sidekiq_7.2
66+
- sidekiq_7.3
6667

6768
steps:
6869
- uses: actions/checkout@v4

.rubocop.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,13 @@ RSpec/ExpectActual:
115115
RSpec/ExpectChange:
116116
EnforcedStyle: block
117117

118-
RSpec/FilePath:
118+
RSpec/SpecFilePathFormat:
119+
Enabled: true
120+
Exclude:
121+
- spec/performance/locksmith_spec.rb
122+
- spec/performance/lock_digest_spec.rb
123+
124+
RSpec/SpecFilePathSuffix:
119125
Enabled: true
120126
Exclude:
121127
- spec/performance/locksmith_spec.rb

Appraisals

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,7 @@ end
1515
appraise "sidekiq-7.2" do
1616
gem "sidekiq", "~> 7.2.0"
1717
end
18+
19+
appraise "sidekiq-7.3" do
20+
gem "sidekiq", "~> 7.3.0"
21+
end

README.md

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ Want to show me some ❤️ for the hard work I do on this gem? You can use the
5959
- [sidekiq-global_id](#sidekiq-global_id)
6060
- [sidekiq-status](#sidekiq-status)
6161
- [Global Configuration](#global-configuration)
62+
- [digest_algorithm](#digest_algorithm)
6263
- [debug_lua](#debug_lua)
6364
- [lock_timeout](#lock_timeout)
6465
- [lock_ttl](#lock_ttl)
@@ -734,17 +735,29 @@ Configure SidekiqUniqueJobs in an initializer or the sidekiq initializer on appl
734735

735736
```ruby
736737
SidekiqUniqueJobs.configure do |config|
737-
config.logger = Sidekiq.logger # default, change at your own discretion
738-
config.logger_enabled = true # default, disable for test environments
739-
config.debug_lua = false # Turn on when debugging
740-
config.lock_info = false # Turn on when debugging
741-
config.lock_ttl = 600 # Expire locks after 10 minutes
742-
config.lock_timeout = nil # turn off lock timeout
743-
config.max_history = 0 # Turn on when debugging
744-
config.reaper = :ruby # :ruby, :lua or :none/nil
745-
config.reaper_count = 1000 # Stop reaping after this many keys
746-
config.reaper_interval = 600 # Reap orphans every 10 minutes
747-
config.reaper_timeout = 150 # Timeout reaper after 2.5 minutes
738+
config.logger = Sidekiq.logger # default, change at your own discretion
739+
config.logger_enabled = true # default, disable for test environments
740+
config.debug_lua = false # Turn on when debugging
741+
config.lock_info = false # Turn on when debugging
742+
config.lock_ttl = 600 # Expire locks after 10 minutes
743+
config.lock_timeout = nil # turn off lock timeout
744+
config.max_history = 0 # Turn on when debugging
745+
config.reaper = :ruby # :ruby, :lua or :none/nil
746+
config.reaper_count = 1000 # Stop reaping after this many keys
747+
config.reaper_interval = 600 # Reap orphans every 10 minutes
748+
config.reaper_timeout = 150 # Timeout reaper after 2.5 minutes
749+
config.digest_algorithm = :modern # Timeout reaper after 2.5 minutes
750+
end
751+
```
752+
#### digest_algorithm
753+
754+
For backwards compatibility this one is set to `:legacy` by the default. If you happen to run into issues with FIPS being enabled on your redis server you might want to set this to `:modern`.
755+
756+
See: https://github.com/mhenrixon/sidekiq-unique-jobs/issues/848 for explanation
757+
758+
```ruby
759+
SidekiqUniqueJobs.configure do |config|
760+
config.digest_algorithm = :modern # Timeout reaper after 2.5 minutes
748761
end
749762
```
750763

gemfiles/sidekiq_7.1.gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ gem "sinatra"
1919
gem "timecop"
2020
gem "toxiproxy"
2121
gem "yard"
22-
gem "sidekiq", "~> 7.0.0"
22+
gem "sidekiq", "~> 7.1.0"
2323

2424
platforms :mri do
2525
gem "concurrent-ruby-ext"

gemfiles/sidekiq_7.2.gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ gem "sinatra"
1919
gem "timecop"
2020
gem "toxiproxy"
2121
gem "yard"
22-
gem "sidekiq", "~> 7.0.0"
22+
gem "sidekiq", "~> 7.2.0"
2323

2424
platforms :mri do
2525
gem "concurrent-ruby-ext"

gemfiles/sidekiq_7.3.gemfile

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# This file was generated by Appraisal
2+
3+
source "https://rubygems.org"
4+
5+
gem "appraisal"
6+
gem "faraday-retry"
7+
gem "gem-release"
8+
gem "github-markup"
9+
gem "rack-test"
10+
gem "rake", "13.0.3"
11+
gem "reek", ">= 5.3"
12+
gem "rspec"
13+
gem "rspec-benchmark"
14+
gem "rspec-html-matchers"
15+
gem "rspec-its"
16+
gem "rubocop-mhenrixon"
17+
gem "simplecov-sublime", ">= 0.21.2", require: false
18+
gem "sinatra"
19+
gem "timecop"
20+
gem "toxiproxy"
21+
gem "yard"
22+
gem "sidekiq", "~> 7.3.0"
23+
24+
platforms :mri do
25+
gem "concurrent-ruby-ext"
26+
end
27+
28+
gemspec path: "../"

lib/sidekiq_unique_jobs/config.rb

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ module SidekiqUniqueJobs
2121
:reaper_resurrector_enabled,
2222
:lock_info,
2323
:raise_on_config_error,
24-
:current_redis_version)
24+
:current_redis_version,
25+
:digest_algorithm)
2526

2627
#
2728
# Shared class for dealing with gem configuration
@@ -118,11 +119,9 @@ class Config < ThreadSafeConfig
118119
#
119120
# @return [3600] check if reaper is dead each 3600 seconds
120121
REAPER_RESURRECTOR_INTERVAL = 3600
121-
122122
#
123123
# @return [false] enable reaper resurrector
124124
REAPER_RESURRECTOR_ENABLED = false
125-
126125
#
127126
# @return [false] while useful it also adds overhead so disable lock_info by default
128127
USE_LOCK_INFO = false
@@ -132,6 +131,9 @@ class Config < ThreadSafeConfig
132131
#
133132
# @return [0.0.0] default redis version is only to avoid NoMethodError on nil
134133
REDIS_VERSION = "0.0.0"
134+
#
135+
# @return [:legacy] default digest algorithm :modern or :legacy
136+
DIGEST_ALGORITHM = :legacy
135137

136138
#
137139
# Returns a default configuration
@@ -198,6 +200,7 @@ def self.default # rubocop:disable Metrics/MethodLength
198200
USE_LOCK_INFO,
199201
RAISE_ON_CONFIG_ERROR,
200202
REDIS_VERSION,
203+
DIGEST_ALGORITHM,
201204
)
202205
end
203206

@@ -304,6 +307,21 @@ def add_strategy(name, klass)
304307
self.strategies = new_strategies
305308
end
306309

310+
#
311+
# Sets digest_algorithm to either :modern or :legacy
312+
#
313+
# @param [Symbol] value
314+
#
315+
# @return [Symbol] the new value
316+
#
317+
def digest_algorithm=(value)
318+
unless [:modern, :legacy].include?(value)
319+
raise ArgumentError, "Invalid digest algorithm: #{value} (should be :modern or :legacy)"
320+
end
321+
322+
super
323+
end
324+
307325
#
308326
# The current version of redis
309327
#

lib/sidekiq_unique_jobs/digests.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class Digests < Redis::SortedSet
1818
EMPTY_KEYS_SEGMENT = ["", "", "", ""].freeze
1919

2020
def initialize(digests_key = DIGESTS)
21-
super(digests_key)
21+
super
2222
end
2323

2424
#

lib/sidekiq_unique_jobs/lock/while_executing.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class WhileExecuting < BaseLock
2323
# @param [Sidekiq::RedisConnection, ConnectionPool] redis_pool the redis connection
2424
#
2525
def initialize(item, callback, redis_pool = nil)
26-
super(item, callback, redis_pool)
26+
super
2727
append_unique_key_suffix
2828
end
2929

0 commit comments

Comments
 (0)