Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add option to silence log output after a time out #598

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion lib/sidekiq_unique_jobs/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -158,6 +162,7 @@ class Config < ThreadSafeConfig
# reaper_count: 1000,
# lock_info: false,
# raise_on_config_error: false,
# silence_lock_timeout: false,
# }>
#
#
Expand All @@ -181,6 +186,7 @@ def self.default # rubocop:disable Metrics/MethodLength
USE_LOCK_INFO,
RAISE_ON_CONFIG_ERROR,
REDIS_VERSION,
SILENCE_LOCK_TIMEOUT,
)
end

Expand Down
2 changes: 2 additions & 0 deletions lib/sidekiq_unique_jobs/locksmith.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
38 changes: 38 additions & 0 deletions spec/sidekiq_unique_jobs/locksmith_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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