Skip to content

Commit

Permalink
Expire older changelog entries first (#698)
Browse files Browse the repository at this point in the history
* Expire older changelog entries first

* Merp

* Fix flaky tests

* Mandatory linter commit

* Ignore smell

* Bump codeclimate
  • Loading branch information
mhenrixon authored Apr 2, 2022
1 parent 0900b2e commit 0c3ecba
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .codeclimate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ plugins:
file: .reek.yml
rubocop:
enabled: false
channel: rubocop-1-21-0
channel: rubocop-1-23-0
config:
file: .rubocop.yml

Expand Down
1 change: 1 addition & 0 deletions .reek.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ detectors:
- SidekiqUniqueJobs::Digests#page
- SidekiqUniqueJobs::InvalidUniqueArguments#initialize
- SidekiqUniqueJobs::InvalidWorker#initialize
- SidekiqUniqueJobs::LockDigest#initialize
- SidekiqUniqueJobs::Locksmith#add_drift
- SidekiqUniqueJobs::Logging#debug_item
- SidekiqUniqueJobs::NotUniqueWorker#initialize
Expand Down
4 changes: 2 additions & 2 deletions lib/sidekiq_unique_jobs/lock_digest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ def self.call(item)
def initialize(item)
@item = item
@worker_class = item[CLASS]
@lock_args = item.slice(LOCK_ARGS, UNIQUE_ARGS).values.first # TODO: Deprecate UNIQUE_ARGS
@lock_prefix = item.slice(LOCK_PREFIX, UNIQUE_PREFIX).values.first # TODO: Deprecate UNIQUE_PREFIX
@lock_args = item[LOCK_ARGS] || item[UNIQUE_ARGS] # TODO: Deprecate UNIQUE_ARGS
@lock_prefix = item[LOCK_PREFIX] || item[UNIQUE_PREFIX] # TODO: Deprecate UNIQUE_PREFIX
end

# Memoized lock_digest
Expand Down
2 changes: 1 addition & 1 deletion lib/sidekiq_unique_jobs/lua/shared/_common.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ local function log(message, prev_jid)
log_debug("ZADD", changelog, current_time, entry);
redis.call("ZADD", changelog, current_time, entry);
local total_entries = redis.call("ZCARD", changelog)
local removed_entries = redis.call("ZREMRANGEBYRANK", changelog, max_history, -1)
local removed_entries = redis.call("ZREMRANGEBYRANK", changelog, 0, -1 * max_history)
if removed_entries > 0 then
log_debug("Removing", removed_entries , "entries from changelog (total entries", total_entries, "exceeds max_history:", max_history ..")");
end
Expand Down
28 changes: 15 additions & 13 deletions lib/sidekiq_unique_jobs/testing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,24 @@ module Sidekiq
#
# @param [Hash<Symbol, Object>] tmp_config the temporary config to use
#
def self.use_options(tmp_config = {})
old_options = default_worker_options.dup
def self.use_options(tmp_config = {}) # rubocop:disable Metrics/MethodLength
if respond_to?(:default_job_options)
default_job_options.clear
self.default_job_options = tmp_config
else
default_worker_options.clear
self.default_worker_options = tmp_config
end

default_worker_options.clear
self.default_worker_options = tmp_config
yield
ensure
default_worker_options.clear
self.default_worker_options =
if respond_to?(:default_job_options)
default_job_options
else
DEFAULT_WORKER_OPTIONS
end

self.default_worker_options = old_options
if respond_to?(:default_job_options)
default_job_options.clear
self.default_job_options = default_job_options
else
default_worker_options.clear
self.default_worker_options = DEFAULT_WORKER_OPTIONS
end
end

#
Expand Down
14 changes: 8 additions & 6 deletions spec/sidekiq_unique_jobs/lock_args_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,22 @@
describe "#filter_by_proc" do
subject(:filter_by_proc) { lock_args.filter_by_proc(args) }

let(:args) { [1, { "test" => "it" }] }

context "when #lock_args_method is a proc" do
let(:filter) { ->(args) { args[1]["test"] } }
let(:args) { [1, 2] }
let(:filter) { ->(args) { args[1] } }

before { allow(lock_args).to receive(:lock_args_method).and_return(filter) }

it { is_expected.to eq("it") }
it { is_expected.to eq(2) }
end

context "when configured globally" do
let(:args) { %w[abc cde] }
let(:filter) { ->(args) { args[1] } }

it "uses global filter" do
Sidekiq.use_options(lock_args_method: ->(args) { args.first }) do
expect(filter_by_proc).to eq(1)
Sidekiq.use_options(lock_args_method: filter) do
expect(filter_by_proc).to eq("cde")
end
end
end
Expand Down

0 comments on commit 0c3ecba

Please sign in to comment.