diff --git a/lib/sidekiq_unique_jobs/config.rb b/lib/sidekiq_unique_jobs/config.rb index 22394276..cb1ca755 100644 --- a/lib/sidekiq_unique_jobs/config.rb +++ b/lib/sidekiq_unique_jobs/config.rb @@ -18,7 +18,8 @@ module SidekiqUniqueJobs :reaper_timeout, :lock_info, :raise_on_config_error, - :current_redis_version) + :current_redis_version, + :silence_lock_timeout) # # Shared class for dealing with gem configuration @@ -118,6 +119,9 @@ class Config < ThreadSafeConfig # # @return [0.0.0] default redis version is only to avoid NoMethodError on nil REDIS_VERSION = "0.0.0" + # + # @return [false] silence timeout log output + SILENCE_LOCK_TIMEOUT = false # # Returns a default configuration @@ -158,6 +162,7 @@ class Config < ThreadSafeConfig # reaper_count: 1000, # lock_info: false, # raise_on_config_error: false, + # silence_lock_timeout: false, # }> # # @@ -181,6 +186,7 @@ def self.default # rubocop:disable Metrics/MethodLength USE_LOCK_INFO, RAISE_ON_CONFIG_ERROR, REDIS_VERSION, + SILENCE_LOCK_TIMEOUT, ) end diff --git a/lib/sidekiq_unique_jobs/locksmith.rb b/lib/sidekiq_unique_jobs/locksmith.rb index 7f4bfe47..348f1a83 100644 --- a/lib/sidekiq_unique_jobs/locksmith.rb +++ b/lib/sidekiq_unique_jobs/locksmith.rb @@ -332,6 +332,8 @@ def taken?(conn) end def warn_about_timeout + return if SidekiqUniqueJobs.config.silence_lock_timeout + log_warn("Timed out after #{config.timeout}s while waiting for primed token (digest: #{key}, job_id: #{job_id})") end diff --git a/spec/sidekiq_unique_jobs/locksmith_spec.rb b/spec/sidekiq_unique_jobs/locksmith_spec.rb index 83c3fc17..e1e9bc01 100644 --- a/spec/sidekiq_unique_jobs/locksmith_spec.rb +++ b/spec/sidekiq_unique_jobs/locksmith_spec.rb @@ -236,4 +236,42 @@ expect(did_we_get_in).to be false end end + + context "when silence_lock_timeout is false" do + let(:logger) { Logger.new("/dev/null") } + + around do |example| + SidekiqUniqueJobs.use_config(silence_lock_timeout: false, logger: logger, &example) + end + + it "warns about not being able to obtain a lock" do + allow(logger).to receive(:warn) + + locksmith_one.lock do + locksmith_two.lock + end + + expect(logger).to have_received(:warn).with( + "Timed out after 0s while waiting for primed token (digest: uniquejobs:randomvalue, job_id: jidmayhem)", + ) + end + end + + context "when silence_lock_timeout is true" do + let(:logger) { Logger.new("/dev/null") } + + around do |example| + SidekiqUniqueJobs.use_config(silence_lock_timeout: true, logger: logger, &example) + end + + it "does not warn about not being able to obtain a lock" do + allow(logger).to receive(:warn) + + locksmith_one.lock do + locksmith_two.lock + end + + expect(logger).not_to have_received(:warn) + end + end end