diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 8f33baa36..f1e330d1f 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -13,8 +13,8 @@ jobs: - uses: actions/checkout@v2 - uses: ruby/setup-ruby@v1 with: - ruby-version: 2.7 - bundler: 2.3.4 + ruby-version: 3.1 + bundler: 2.3.6 bundler-cache: true - run: bin/bundle --jobs=$(nproc) --retry=$(nproc) - run: bin/rubocop -P @@ -28,8 +28,8 @@ jobs: - uses: actions/checkout@v2 - uses: ruby/setup-ruby@v1 with: - ruby-version: 2.7 - bundler: 2.3.4 + ruby-version: 3.1 + bundler: 2.3.6 bundler-cache: true - run: bin/bundle --jobs=$(nproc) --retry=$(nproc) - run: bin/reek . diff --git a/.github/workflows/rspec.yml b/.github/workflows/rspec.yml index e14e4bf7b..bf0111e82 100644 --- a/.github/workflows/rspec.yml +++ b/.github/workflows/rspec.yml @@ -17,8 +17,8 @@ jobs: - uses: actions/checkout@v2 - uses: ruby/setup-ruby@v1 with: - ruby-version: 2.7 - bundler: 2.3.4 + ruby-version: 3.1 + bundler: 2.3.6 bundler-cache: true - name: Install Code Climate reporter diff --git a/.reek.yml b/.reek.yml index 36f40b6ee..29d3e7821 100644 --- a/.reek.yml +++ b/.reek.yml @@ -7,7 +7,7 @@ exclude_paths: - myapp - spec - tmp - - vendor/bundle + - vendor detectors: BooleanParameter: exclude: @@ -102,6 +102,7 @@ detectors: - SidekiqUniqueJobs::Changelog#entries - SidekiqUniqueJobs::Changelog#page - SidekiqUniqueJobs::Digests#page + - SidekiqUniqueJobs::Lock#lock - SidekiqUniqueJobs::Locksmith#create_lock - SidekiqUniqueJobs::Locksmith#lock! - SidekiqUniqueJobs::Middleware#self.configure_client diff --git a/Appraisals b/Appraisals index fa71bba83..d792f698d 100644 --- a/Appraisals +++ b/Appraisals @@ -27,3 +27,11 @@ end appraise "sidekiq-6.2" do gem "sidekiq", "~> 6.2.2" end + +appraise "sidekiq-6.3" do + gem "sidekiq", "~> 6.3.0" +end + +appraise "sidekiq-6.4" do + gem "sidekiq", "~> 6.4.0" +end diff --git a/gemfiles/sidekiq_6.3.gemfile b/gemfiles/sidekiq_6.3.gemfile new file mode 100644 index 000000000..39f9effaf --- /dev/null +++ b/gemfiles/sidekiq_6.3.gemfile @@ -0,0 +1,27 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "appraisal" +gem "gem-release" +gem "github-markup" +gem "rack-test" +gem "rake", "13.0.3" +gem "reek", ">= 5.3" +gem "rspec" +gem "rspec-benchmark" +gem "rspec-html-matchers" +gem "rspec-its" +gem "rubocop-mhenrixon" +gem "simplecov-sublime", ">= 0.21.2", require: false +gem "sinatra" +gem "timecop" +gem "yard" +gem "sidekiq", "~> 6.3.0" + +platforms :mri do + gem "concurrent-ruby-ext" + gem "hiredis" +end + +gemspec path: "../" diff --git a/gemfiles/sidekiq_6.4.gemfile b/gemfiles/sidekiq_6.4.gemfile new file mode 100644 index 000000000..33c10d37f --- /dev/null +++ b/gemfiles/sidekiq_6.4.gemfile @@ -0,0 +1,27 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "appraisal" +gem "gem-release" +gem "github-markup" +gem "rack-test" +gem "rake", "13.0.3" +gem "reek", ">= 5.3" +gem "rspec" +gem "rspec-benchmark" +gem "rspec-html-matchers" +gem "rspec-its" +gem "rubocop-mhenrixon" +gem "simplecov-sublime", ">= 0.21.2", require: false +gem "sinatra" +gem "timecop" +gem "yard" +gem "sidekiq", "~> 6.4.0" + +platforms :mri do + gem "concurrent-ruby-ext" + gem "hiredis" +end + +gemspec path: "../" diff --git a/lib/sidekiq_unique_jobs/changelog.rb b/lib/sidekiq_unique_jobs/changelog.rb index 4d938b049..b802bfaad 100644 --- a/lib/sidekiq_unique_jobs/changelog.rb +++ b/lib/sidekiq_unique_jobs/changelog.rb @@ -62,9 +62,9 @@ def entries(pattern: SCAN_PATTERN, count: DEFAULT_COUNT) # def page(cursor: 0, pattern: "*", page_size: 100) redis do |conn| - total_size, result = conn.multi do - conn.zcard(key) - conn.zscan(key, cursor, match: pattern, count: page_size) + total_size, result = conn.multi do |pipeline| + pipeline.zcard(key) + pipeline.zscan(key, cursor, match: pattern, count: page_size) end [ diff --git a/lib/sidekiq_unique_jobs/digests.rb b/lib/sidekiq_unique_jobs/digests.rb index e70ab92f9..c6552116f 100644 --- a/lib/sidekiq_unique_jobs/digests.rb +++ b/lib/sidekiq_unique_jobs/digests.rb @@ -95,9 +95,9 @@ def entries(pattern: SCAN_PATTERN, count: DEFAULT_COUNT) # def page(cursor: 0, pattern: SCAN_PATTERN, page_size: 100) redis do |conn| - total_size, digests = conn.multi do - conn.zcard(key) - conn.zscan(key, cursor, match: pattern, count: page_size) + total_size, digests = conn.multi do |pipeline| + pipeline.zcard(key) + pipeline.zscan(key, cursor, match: pattern, count: page_size) end [ diff --git a/lib/sidekiq_unique_jobs/lock.rb b/lib/sidekiq_unique_jobs/lock.rb index 29444b726..dcb2d3bac 100644 --- a/lib/sidekiq_unique_jobs/lock.rb +++ b/lib/sidekiq_unique_jobs/lock.rb @@ -62,13 +62,13 @@ def initialize(key, time: nil) # def lock(job_id, lock_info = {}) redis do |conn| - conn.multi do - conn.set(key.digest, job_id) - conn.hset(key.locked, job_id, now_f) + conn.multi do |pipeline| + pipeline.set(key.digest, job_id) + pipeline.hset(key.locked, job_id, now_f) info.set(lock_info) - conn.zadd(key.digests, now_f, key.digest) - conn.zadd(key.changelog, now_f, changelog_json(job_id, "queue.lua", "Queued")) - conn.zadd(key.changelog, now_f, changelog_json(job_id, "lock.lua", "Locked")) + pipeline.zadd(key.digests, now_f, key.digest) + pipeline.zadd(key.changelog, now_f, changelog_json(job_id, "queue.lua", "Queued")) + pipeline.zadd(key.changelog, now_f, changelog_json(job_id, "lock.lua", "Locked")) end end end diff --git a/lib/sidekiq_unique_jobs/sidekiq_unique_ext.rb b/lib/sidekiq_unique_jobs/sidekiq_unique_ext.rb index f5168c8be..9a3fd699b 100644 --- a/lib/sidekiq_unique_jobs/sidekiq_unique_ext.rb +++ b/lib/sidekiq_unique_jobs/sidekiq_unique_ext.rb @@ -68,7 +68,7 @@ def delete(score, job_id) prepend UniqueExtension end - if Sidekiq.const_defined?("JobRecord") + if Sidekiq.const_defined?(:JobRecord) # See Sidekiq::Api class JobRecord # diff --git a/lib/sidekiq_unique_jobs/timing.rb b/lib/sidekiq_unique_jobs/timing.rb index cf42ef59c..0558ba6ab 100644 --- a/lib/sidekiq_unique_jobs/timing.rb +++ b/lib/sidekiq_unique_jobs/timing.rb @@ -48,7 +48,7 @@ def now_f # @return [Float] # def clock_stamp - if Process.const_defined?("CLOCK_MONOTONIC") + if Process.const_defined?(:CLOCK_MONOTONIC) Process.clock_gettime(Process::CLOCK_MONOTONIC) else now_f diff --git a/lib/sidekiq_unique_jobs/web/helpers.rb b/lib/sidekiq_unique_jobs/web/helpers.rb index 1adc7f35e..621168cae 100644 --- a/lib/sidekiq_unique_jobs/web/helpers.rb +++ b/lib/sidekiq_unique_jobs/web/helpers.rb @@ -27,7 +27,7 @@ module Helpers # @return [String] the file contents of the template # def unique_template(name) - File.open(unique_filename(name)).read + File.read(unique_filename(name)) end # diff --git a/spec/jobs/another_unique_job_job_spec.rb b/spec/jobs/another_unique_job_job_spec.rb index be7f827f4..fb3eddc47 100644 --- a/spec/jobs/another_unique_job_job_spec.rb +++ b/spec/jobs/another_unique_job_job_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -if Sidekiq.const_defined?("JobRecord") +if Sidekiq.const_defined?(:JobRecord) RSpec.describe AnotherUniqueJobJob do it_behaves_like "sidekiq with options" do let(:options) do diff --git a/spec/sidekiq/api_spec.rb b/spec/sidekiq/api_spec.rb index 12eef8c00..e6fdf8777 100644 --- a/spec/sidekiq/api_spec.rb +++ b/spec/sidekiq/api_spec.rb @@ -49,7 +49,7 @@ end end - if Sidekiq.const_defined?("JobRecord") + if Sidekiq.const_defined?(:JobRecord) describe Sidekiq::JobRecord::UniqueExtension do it "deletes uniqueness lock on delete" do jid = JustAWorker.perform_async(roo: "baf") diff --git a/spec/sidekiq_unique_jobs/lock/until_and_while_executing_spec.rb b/spec/sidekiq_unique_jobs/lock/until_and_while_executing_spec.rb index df597fa29..6c11efb53 100644 --- a/spec/sidekiq_unique_jobs/lock/until_and_while_executing_spec.rb +++ b/spec/sidekiq_unique_jobs/lock/until_and_while_executing_spec.rb @@ -27,7 +27,7 @@ let(:lock_timeout) { nil } let(:sleepy_time) { 0 } - if Sidekiq.const_defined?("JobRecord") + if Sidekiq.const_defined?(:JobRecord) let(:worker_class) { AnotherUniqueJobJob } else let(:worker_class) { UntilAndWhileExecutingJob } diff --git a/spec/sidekiq_unique_jobs/middleware/client_spec.rb b/spec/sidekiq_unique_jobs/middleware/client_spec.rb index f3b044b04..3fff54b34 100644 --- a/spec/sidekiq_unique_jobs/middleware/client_spec.rb +++ b/spec/sidekiq_unique_jobs/middleware/client_spec.rb @@ -35,14 +35,6 @@ expect(schedule_count).to eq(20) end - - it "schedules allows jobs to be scheduled" do - [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20].each do |x| - PlainClass.delay_for(x, queue: "default", unique: :while_executing).run(1) - end - - expect(schedule_count).to eq(20) - end end it "does not push duplicate messages when unique_args are filtered with a proc" do @@ -81,12 +73,6 @@ expect(queue_count("customqueue")).to eq(1) end - it "does not queue duplicates when when calling delay", sidekiq_ver: "< 7.0" do - Array.new(10) { PlainClass.delay(lock: :until_executed, queue: "customqueue").run(1) } - - expect(queue_count("customqueue")).to eq(1) - end - context "when class is not unique" do it "pushes duplicate messages" do Array.new(10) do diff --git a/spec/sidekiq_unique_jobs/options_with_fallback_spec.rb b/spec/sidekiq_unique_jobs/options_with_fallback_spec.rb index 3d1be33b2..e5ffdfcac 100644 --- a/spec/sidekiq_unique_jobs/options_with_fallback_spec.rb +++ b/spec/sidekiq_unique_jobs/options_with_fallback_spec.rb @@ -161,16 +161,5 @@ def initialize(item, options, worker_class = nil) it { is_expected.to eq(SimpleWorker.get_sidekiq_options) } end - - context "when default_worker_options has been configured" do - let(:worker_class) { PlainClass } - let(:default_worker_options) { { "lock" => :while_executing } } - - it do - Sidekiq.use_options(default_worker_options) do - expect(class_options).to include(default_worker_options) - end - end - end end end diff --git a/spec/sidekiq_unique_jobs/rspec/matchers/have_valid_sidekiq_options_spec.rb b/spec/sidekiq_unique_jobs/rspec/matchers/have_valid_sidekiq_options_spec.rb index 9583aaba4..5996309fa 100644 --- a/spec/sidekiq_unique_jobs/rspec/matchers/have_valid_sidekiq_options_spec.rb +++ b/spec/sidekiq_unique_jobs/rspec/matchers/have_valid_sidekiq_options_spec.rb @@ -2,7 +2,7 @@ RSpec.describe SidekiqUniqueJobs::RSpec::Matchers::HaveValidSidekiqOptions do describe "#matches?" do - if Sidekiq.const_defined?("JobRecord") + if Sidekiq.const_defined?(:JobRecord) context "when sidekiq options are valid" do it { expect(AnotherUniqueJob).to have_valid_sidekiq_options } end diff --git a/spec/support/jobs/another_unique_job_job.rb b/spec/support/jobs/another_unique_job_job.rb index 78541f111..f85ea3184 100644 --- a/spec/support/jobs/another_unique_job_job.rb +++ b/spec/support/jobs/another_unique_job_job.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true # :nocov: -if Sidekiq.const_defined?("JobRecord") +if Sidekiq.const_defined?(:JobRecord) require "sidekiq/job" class AnotherUniqueJobJob diff --git a/spec/support/sidekiq_meta.rb b/spec/support/sidekiq_meta.rb index fbfb06928..881c20c9e 100644 --- a/spec/support/sidekiq_meta.rb +++ b/spec/support/sidekiq_meta.rb @@ -25,11 +25,6 @@ def sidekiq_redis_driver Sidekiq.redis = redis flush_redis - if SidekiqUniqueJobs::VersionCheck.satisfied?(Sidekiq::VERSION, "< 7.0.0") - enable_delay = defined?(Sidekiq::Extensions) && Sidekiq::Extensions.respond_to?(:enable_delay!) - Sidekiq::Extensions.enable_delay! if enable_delay - end - if (sidekiq = example.metadata.fetch(:sidekiq, :disable)) sidekiq = :fake if sidekiq == true Sidekiq::Testing.send("#{sidekiq}!") diff --git a/spec/support/simulate_lock.rb b/spec/support/simulate_lock.rb index 9699586ab..0ad39729c 100644 --- a/spec/support/simulate_lock.rb +++ b/spec/support/simulate_lock.rb @@ -19,14 +19,14 @@ def lock_jid(key, jid, ttl: nil, lock_type: :until_executed) def simulate_lock(key, job_id) redis do |conn| - conn.multi do - conn.set(key.digest, job_id) - conn.lpush(key.queued, job_id) - conn.lpush(key.primed, job_id) - conn.hset(key.locked, job_id, now_f) - conn.zadd(key.digests, now_f, key.digest) - conn.zadd(key.changelog, now_f, changelog_entry(key, job_id, "queue.lua", "Queued")) - conn.zadd(key.changelog, now_f, changelog_entry(key, job_id, "lock.lua", "Locked")) + conn.multi do |pipeline| + pipeline.set(key.digest, job_id) + pipeline.lpush(key.queued, job_id) + pipeline.lpush(key.primed, job_id) + pipeline.hset(key.locked, job_id, now_f) + pipeline.zadd(key.digests, now_f, key.digest) + pipeline.zadd(key.changelog, now_f, changelog_entry(key, job_id, "queue.lua", "Queued")) + pipeline.zadd(key.changelog, now_f, changelog_entry(key, job_id, "lock.lua", "Locked")) end end end diff --git a/spec/support/workers/plain_class.rb b/spec/support/workers/plain_class.rb deleted file mode 100644 index 0949a68e0..000000000 --- a/spec/support/workers/plain_class.rb +++ /dev/null @@ -1,13 +0,0 @@ -# frozen_string_literal: true - -# :nocov: - -class PlainClass - def self.run(one) - [one] - end - - def run(one) - [one] - end -end diff --git a/spec/workers/plain_class_spec.rb b/spec/workers/plain_class_spec.rb deleted file mode 100644 index 01b3f037c..000000000 --- a/spec/workers/plain_class_spec.rb +++ /dev/null @@ -1,19 +0,0 @@ -# frozen_string_literal: true - -RSpec.describe PlainClass do - describe ".run" do - subject { described_class.run(arg) } - - let(:arg) { "argument" } - - it { is_expected.to eq(["argument"]) } - end - - describe "#run" do - subject { described_class.new.run(arg) } - - let(:arg) { "another argument" } - - it { is_expected.to eq(["another argument"]) } - end -end