Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/github_actions/actions/checkout-4
Browse files Browse the repository at this point in the history
  • Loading branch information
mhenrixon committed Nov 11, 2023
2 parents 969f5b9 + 8980da7 commit 773f8d3
Show file tree
Hide file tree
Showing 24 changed files with 142 additions and 85 deletions.
15 changes: 0 additions & 15 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,3 @@ jobs:
bundler-cache: true
- run: bin/bundle --jobs=$(nproc) --retry=$(nproc)
- run: bin/rubocop -P

reek:
runs-on: ubuntu-latest
strategy:
fail-fast: true

steps:
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
ruby-version: 3.1
bundler: 2.4.12
bundler-cache: true
- run: bin/bundle --jobs=$(nproc) --retry=$(nproc)
- run: bin/reek .
34 changes: 32 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,41 @@
# Changelog

## [Unreleased](https://github.com/mhenrixon/sidekiq-unique-jobs/tree/HEAD)
## [v8.0.4](https://github.com/mhenrixon/sidekiq-unique-jobs/tree/v8.0.4) (2023-11-11)

[Full Changelog](https://github.com/mhenrixon/sidekiq-unique-jobs/compare/v8.0.3...HEAD)
[Full Changelog](https://github.com/mhenrixon/sidekiq-unique-jobs/compare/v7.1.30...v8.0.4)

**Implemented enhancements:**

- fix: ignore reek for now [\#818](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/818) ([mhenrixon](https://github.com/mhenrixon))
- fix\(ci\): allow tests to run in docker [\#805](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/805) ([Earlopain](https://github.com/Earlopain))
- chore\(deps\): bump'n lint'n such [\#797](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/797) ([mhenrixon](https://github.com/mhenrixon))

**Fixed bugs:**

- Sidekiq 7: Unsupported command argument type: TrueClass [\#816](https://github.com/mhenrixon/sidekiq-unique-jobs/issues/816)
- fix\(web\): don't show bogus lock digests [\#804](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/804) ([Earlopain](https://github.com/Earlopain))

**Closed issues:**

- register\_reaper\_process nx: true crash Sidekiq on startup [\#817](https://github.com/mhenrixon/sidekiq-unique-jobs/issues/817)
- Should client middleware also be added to the Sidekiq server config? [\#803](https://github.com/mhenrixon/sidekiq-unique-jobs/issues/803)
- 8.0.1 Time on locks & changelog UI is incorrect/wrong [\#761](https://github.com/mhenrixon/sidekiq-unique-jobs/issues/761)
- Job executed twice when reaper runs [\#738](https://github.com/mhenrixon/sidekiq-unique-jobs/issues/738)

**Merged pull requests:**

- fix: Sidekiq 7.2 throws TypeError: Unsupported command argument type: TrueClass when using byscore: true [\#815](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/815) ([Amnesthesia](https://github.com/Amnesthesia))
- Add sidekiq\_option for on-conflict-reschedule perform\_in time [\#813](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/813) ([mgmarlow](https://github.com/mgmarlow))
- Handle strategy fallbacks properly [\#809](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/809) ([matejrisek](https://github.com/matejrisek))
- Fix CI status badge [\#802](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/802) ([tagliala](https://github.com/tagliala))

## [v7.1.30](https://github.com/mhenrixon/sidekiq-unique-jobs/tree/v7.1.30) (2023-07-17)

[Full Changelog](https://github.com/mhenrixon/sidekiq-unique-jobs/compare/v8.0.3...v7.1.30)

**Closed issues:**

- Release new gem version with "fix replace deprecated rpoplpush w/lmove" [\#795](https://github.com/mhenrixon/sidekiq-unique-jobs/issues/795)
- Redis has deprecated the `rpoplpush`command [\#793](https://github.com/mhenrixon/sidekiq-unique-jobs/issues/793)
- Deprecation Warning: Use of rpoplpush command in Redis [\#792](https://github.com/mhenrixon/sidekiq-unique-jobs/issues/792)
- Logging::Middleware.context can include empty string as key when lock is not set in job hash [\#785](https://github.com/mhenrixon/sidekiq-unique-jobs/issues/785)
Expand Down
14 changes: 10 additions & 4 deletions lib/sidekiq_unique_jobs/lock_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,20 @@ def errors_as_string

# the strategy to use as conflict resolution from sidekiq client
def on_client_conflict
@on_client_conflict ||= on_conflict["client"] || on_conflict[:client] if on_conflict.is_a?(Hash)
@on_client_conflict ||= on_conflict
@on_client_conflict ||= if on_conflict.is_a?(Hash)
on_conflict["client"] || on_conflict[:client]
else
on_conflict
end
end

# the strategy to use as conflict resolution from sidekiq server
def on_server_conflict
@on_server_conflict ||= on_conflict["server"] || on_conflict[:server] if on_conflict.is_a?(Hash)
@on_server_conflict ||= on_conflict
@on_server_conflict ||= if on_conflict.is_a?(Hash)
on_conflict["server"] || on_conflict[:server]
else
on_conflict
end
end
end
end
6 changes: 5 additions & 1 deletion lib/sidekiq_unique_jobs/on_conflict/reschedule.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def initialize(item, redis_pool = nil)
# This will mess up sidekiq stats because a new job is created
def call
if sidekiq_job_class?
if job_class.set(queue: item["queue"].to_sym).perform_in(5, *item[ARGS])
if job_class.set(queue: item["queue"].to_sym).perform_in(schedule_in, *item[ARGS])
reflect(:rescheduled, item)
else
reflect(:reschedule_failed, item)
Expand All @@ -30,6 +30,10 @@ def call
reflect(:unknown_sidekiq_worker, item)
end
end

def schedule_in
job_class.get_sidekiq_options["schedule_in"] || 5
end
end
end
end
4 changes: 2 additions & 2 deletions lib/sidekiq_unique_jobs/orphans/manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def enabled?
# @return [void]
#
def register_reaper_process
redis { |conn| conn.set(UNIQUE_REAPER, current_timestamp, nx: true, ex: drift_reaper_interval) }
redis { |conn| conn.set(UNIQUE_REAPER, current_timestamp, "nx", "ex", drift_reaper_interval) }
end

#
Expand All @@ -202,7 +202,7 @@ def register_reaper_process
# @return [void]
#
def refresh_reaper_mutex
redis { |conn| conn.set(UNIQUE_REAPER, current_timestamp, ex: drift_reaper_interval) }
redis { |conn| conn.set(UNIQUE_REAPER, current_timestamp, "ex", drift_reaper_interval) }
end

#
Expand Down
2 changes: 1 addition & 1 deletion lib/sidekiq_unique_jobs/orphans/ruby_reaper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def call
def expired_digests
max_score = (start_time - reaper_timeout).to_f

conn.zrange(EXPIRING_DIGESTS, 0, max_score, byscore: true)
conn.zrange(EXPIRING_DIGESTS, 0, max_score, "byscore")
end

#
Expand Down
7 changes: 4 additions & 3 deletions lib/sidekiq_unique_jobs/redis/sorted_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ class SortedSet < Entity
# @return [Hash] when given with_scores: true
#
def entries(with_scores: true)
entrys = redis { |conn| conn.zrange(key, 0, -1, withscores: with_scores) }
return entrys unless with_scores
return redis { |conn| conn.zrange(key, 0, -1) } unless with_scores

entrys.each_with_object({}) { |pair, hash| hash[pair[0]] = pair[1] }
redis { |conn| conn.zrange(key, 0, -1, "withscores") }.each_with_object({}) do |pair, hash|
hash[pair[0]] = pair[1]
end
end

#
Expand Down
2 changes: 1 addition & 1 deletion lib/sidekiq_unique_jobs/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
module SidekiqUniqueJobs
#
# @return [String] the current SidekiqUniqueJobs version
VERSION = "8.0.4"
VERSION = "8.0.5"
end
4 changes: 3 additions & 1 deletion spec/performance/lock_digest_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

RSpec.describe SidekiqUniqueJobs::LockDigest, perf: true do
# rubocop:disable RSpec/SpecFilePathFormat, RSpec/FilePath
RSpec.describe SidekiqUniqueJobs::LockDigest, :perf do
let(:lock_digest) { described_class.new(item) }
let(:job_class) { UntilExecutedJob }
let(:class_name) { worker_class.to_s }
Expand Down Expand Up @@ -50,3 +51,4 @@
end
end
end
# rubocop:enable RSpec/SpecFilePathFormat, RSpec/FilePath
4 changes: 3 additions & 1 deletion spec/performance/locksmith_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

RSpec.describe SidekiqUniqueJobs::Locksmith, perf: true do
# rubocop:disable RSpec/SpecFilePathFormat, RSpec/FilePath
RSpec.describe SidekiqUniqueJobs::Locksmith, :perf do
let(:locksmith_one) { described_class.new(item_one) }
let(:locksmith_two) { described_class.new(item_two) }

Expand Down Expand Up @@ -49,3 +50,4 @@
expect { locksmith_one.lock {} }.to perform_allocation(Array => 12_640, Hash => 13_888).bytes
end
end
# rubocop:enable RSpec/SpecFilePathFormat, RSpec/FilePath
28 changes: 14 additions & 14 deletions spec/sidekiq_unique_jobs/changelog_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

it "adds a new entry" do
expect { add }.to change { entity.entries.size }.by(1)
expect(add).to be == 1
expect(add).to eq 1
end
end

Expand All @@ -39,14 +39,14 @@

it "clears out all entries" do
expect { clear }.to change { entity.entries.size }.by(-1)
expect(clear).to be == 1
expect(clear).to eq 1
end
end

context "without entries" do
it "returns 0 (zero)" do
expect { clear }.not_to change { entity.entries.size }
expect(clear).to be == 0
expect(clear).to eq 0
end
end
end
Expand All @@ -55,27 +55,27 @@
subject(:exist?) { entity.exist? }

context "when no entries exist" do
it { is_expected.to be == false }
it { is_expected.to be false }
end

context "when entries exist" do
before { simulate_lock(key, job_id) }

it { is_expected.to be == true }
it { is_expected.to be true }
end
end

describe "#pttl" do
subject(:pttl) { entity.pttl }

context "when no entries exist" do
it { is_expected.to be == -2 }
it { is_expected.to eq(-2) }
end

context "when entries exist without expiration" do
before { simulate_lock(key, job_id) }

it { is_expected.to be == -1 }
it { is_expected.to eq(-1) }
end

context "when entries exist with expiration" do
Expand All @@ -92,13 +92,13 @@
subject(:ttl) { entity.ttl }

context "when no entries exist" do
it { is_expected.to be == -2 }
it { is_expected.to eq(-2) }
end

context "when entries exist without expiration" do
before { simulate_lock(key, job_id) }

it { is_expected.to be == -1 }
it { is_expected.to eq(-1) }
end

context "when entries exist with expiration" do
Expand All @@ -107,15 +107,15 @@
expire(key.changelog, 600)
end

it { is_expected.to be == 600 }
it { is_expected.to eq 600 }
end
end

describe "#expires?" do
subject(:expires?) { entity.expires? }

context "when no entries exist" do
it { is_expected.to be == false }
it { is_expected.to be false }
end

context "when entries exist" do
Expand All @@ -124,21 +124,21 @@
expire(key.changelog, 600)
end

it { is_expected.to be == true }
it { is_expected.to be true }
end
end

describe "#count" do
subject(:count) { entity.count }

context "when no entries exist" do
it { is_expected.to be == 0 }
it { is_expected.to eq 0 }
end

context "when entries exist" do
before { simulate_lock(key, job_id) }

it { is_expected.to be == 2 }
it { is_expected.to eq 2 }
end
end

Expand Down
10 changes: 5 additions & 5 deletions spec/sidekiq_unique_jobs/cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@
jobs del PATTERN
Options:
d, [--dry-run], [--no-dry-run] # set to false to perform deletion
c, [--count=N] # The max number of digests to return
# Default: 1000
-d, [--dry-run], [--no-dry-run] # set to false to perform deletion
-c, [--count=N] # The max number of digests to return
# Default: 1000
deletes unique digests from redis by pattern
HEADER
Expand All @@ -55,8 +55,8 @@
jobs list PATTERN
Options:
c, [--count=N] # The max number of digests to return
# Default: 1000
-c, [--count=N] # The max number of digests to return
# Default: 1000
list all unique digests and their expiry time
HEADER
Expand Down
4 changes: 2 additions & 2 deletions spec/sidekiq_unique_jobs/configuration_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

# rubocop:disable RSpec/FilePath
# rubocop:disable RSpec/SpecFilePathFormat, RSpec/FilePath
RSpec.describe SidekiqUniqueJobs do
describe "define custom lock strategies" do
subject(:middleware_call) do
Expand Down Expand Up @@ -65,4 +65,4 @@ def lock
end
end
end
# rubocop:enable RSpec/FilePath
# rubocop:enable RSpec/SpecFilePathFormat, RSpec/FilePath
12 changes: 12 additions & 0 deletions spec/sidekiq_unique_jobs/lock_config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,12 @@

it { is_expected.to eq(:replace) }
end

context "when on_conflict is defined only for server" do
let(:on_conflict) { { server: :log } }

it { is_expected.to be_nil }
end
end

describe "#on_server_conflict" do
Expand All @@ -158,5 +164,11 @@

it { is_expected.to eq(:reschedule) }
end

context "when on_conflict is defined only for client" do
let(:on_conflict) { { client: :log } }

it { is_expected.to be_nil }
end
end
end
12 changes: 6 additions & 6 deletions spec/sidekiq_unique_jobs/lua/delete_by_digest_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@
it "deletes the expected keys from redis" do
expect(delete_by_digest).to eq(8)

expect(queued.count).to be == 0
expect(primed.count).to be == 0
expect(locked.count).to be == 0
expect(queued.count).to eq 0
expect(primed.count).to eq 0
expect(locked.count).to eq 0

expect(run_queued.count).to be == 0
expect(run_primed.count).to be == 0
expect(run_locked.count).to be == 0
expect(run_queued.count).to eq 0
expect(run_primed.count).to eq 0
expect(run_locked.count).to eq 0
end
end
2 changes: 1 addition & 1 deletion spec/sidekiq_unique_jobs/lua/lock_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
let(:now_f) { SidekiqUniqueJobs.now_f }
let(:lock_limit) { 1 }

shared_context "with a primed key", with_primed_key: true do
shared_context "with a primed key", :with_primed_key do
before do
call_script(:queue, key.to_a, argv_one)
rpoplpush(key.queued, key.primed)
Expand Down
Loading

0 comments on commit 773f8d3

Please sign in to comment.