Skip to content

Commit

Permalink
Prepare for redis 5.0.0 (#680)
Browse files Browse the repository at this point in the history
* Prepare for redis 5.0.0

* Run on ruby 3.1

* Mandatory linter commit

* Mandatory linter commit
  • Loading branch information
mhenrixon authored Feb 3, 2022
1 parent 9419fd0 commit 66d4e2a
Show file tree
Hide file tree
Showing 23 changed files with 98 additions and 97 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 .
4 changes: 2 additions & 2 deletions .github/workflows/rspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion .reek.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ exclude_paths:
- myapp
- spec
- tmp
- vendor/bundle
- vendor
detectors:
BooleanParameter:
exclude:
Expand Down Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions Appraisals
Original file line number Diff line number Diff line change
Expand Up @@ -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
27 changes: 27 additions & 0 deletions gemfiles/sidekiq_6.3.gemfile
Original file line number Diff line number Diff line change
@@ -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: "../"
27 changes: 27 additions & 0 deletions gemfiles/sidekiq_6.4.gemfile
Original file line number Diff line number Diff line change
@@ -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: "../"
6 changes: 3 additions & 3 deletions lib/sidekiq_unique_jobs/changelog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

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

[
Expand Down
12 changes: 6 additions & 6 deletions lib/sidekiq_unique_jobs/lock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/sidekiq_unique_jobs/sidekiq_unique_ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
Expand Down
2 changes: 1 addition & 1 deletion lib/sidekiq_unique_jobs/timing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/sidekiq_unique_jobs/web/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

#
Expand Down
2 changes: 1 addition & 1 deletion spec/jobs/another_unique_job_job_spec.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/sidekiq/api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
14 changes: 0 additions & 14 deletions spec/sidekiq_unique_jobs/middleware/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
11 changes: 0 additions & 11 deletions spec/sidekiq_unique_jobs/options_with_fallback_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/support/jobs/another_unique_job_job.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

# :nocov:
if Sidekiq.const_defined?("JobRecord")
if Sidekiq.const_defined?(:JobRecord)
require "sidekiq/job"

class AnotherUniqueJobJob
Expand Down
5 changes: 0 additions & 5 deletions spec/support/sidekiq_meta.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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}!")
Expand Down
16 changes: 8 additions & 8 deletions spec/support/simulate_lock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 0 additions & 13 deletions spec/support/workers/plain_class.rb

This file was deleted.

19 changes: 0 additions & 19 deletions spec/workers/plain_class_spec.rb

This file was deleted.

0 comments on commit 66d4e2a

Please sign in to comment.