Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Sidekiq 7 upgrade #47

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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: 4 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ jobs:
strategy:
matrix:
ruby-version: ['3.1', '2.7']
sidekiq-version: ['4', '5', '6.0', '6.1', '6.x']
sidekiq-version: ['4', '5', '6.0', '6.1', '6.x', '7.x']

steps:
- uses: actions/checkout@v3

- name: Set up Ruby ${{ matrix.ruby-version }}
uses: ruby/setup-ruby@359bebbc29cbe6c87da6bc9ea3bc930432750108
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby-version }}

Expand All @@ -32,7 +32,7 @@ jobs:
run: bundle exec --gemfile=gemfiles/sidekiq_${{ matrix.sidekiq-version }}.gemfile rspec

- name: Coveralls
uses: coverallsapp/github-action@v1
uses: coverallsapp/github-action@v2
with:
flag-name: run-${{ join(matrix.*, '-') }}
parallel: true
Expand All @@ -43,6 +43,6 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Coveralls Finished
uses: coverallsapp/github-action@v1
uses: coverallsapp/github-action@v2
with:
parallel-finished: true
5 changes: 5 additions & 0 deletions gemfiles/sidekiq_7.x.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
source "https://rubygems.org"

gem 'sidekiq', '~> 7.0.0'

gemspec path: '../'
2 changes: 2 additions & 0 deletions lib/sidekiq-rate-limiter/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
Sidekiq.options[:fetch] = Sidekiq::RateLimiter::Fetch
elsif (Sidekiq::VERSION < '6.5.0') # Sidekiq config was redesigned in https://github.com/mperham/sidekiq/pull/5340
Sidekiq.options[:fetch] = Sidekiq::RateLimiter::Fetch.new(Sidekiq.options)
elsif (Sidekiq::VERSION >= '7.0')
config[:fetch_class] = Sidekiq::RateLimiter::Fetch
else
Sidekiq[:fetch] = Sidekiq::RateLimiter::Fetch.new(Sidekiq)
end
Expand Down
2 changes: 1 addition & 1 deletion sidekiq-rate-limiter.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ Gem::Specification.new do |s|
s.add_development_dependency "simplecov"
s.add_development_dependency "simplecov-lcov", '~> 0.8.0'

s.add_dependency "sidekiq", ">= 4.0", "< 7.0"
s.add_dependency "sidekiq", ">= 4.0", "< 8.0"
s.add_dependency "redis_rate_limiter"
end
16 changes: 14 additions & 2 deletions spec/sidekiq-rate-limiter/fetch_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ def perform(arg1, arg2); end
let(:options) do
if Sidekiq::VERSION =~ /^(4|5|6\.[0-4])/
{ queues: [queue, another_queue, another_queue] }
elsif Sidekiq::VERSION.start_with?('7.')
config = Sidekiq.default_configuration
config.queues = [queue, another_queue, another_queue]
config.default_capsule
else
Sidekiq.tap { |s| s[:queues] = [queue, another_queue, another_queue] }
end
Expand Down Expand Up @@ -59,8 +63,16 @@ def perform(arg1, arg2); end
timeout = _timeout
end

fetch = described_class.new options.merge!(:strict => true)
expect(fetch.queues_cmd).to eql(["queue:#{queue}", "queue:#{another_queue}", timeout])
expected = [ "queue:#{queue}", "queue:#{another_queue}" ]

if !Sidekiq::VERSION.start_with?('7.')
options.merge!(strict: true)
expected.push(timeout)
end

fetch = described_class.new(options)

expect(fetch.queues_cmd).to eql(expected)
end

it 'should retrieve work', queuing: true do
Expand Down
8 changes: 6 additions & 2 deletions spec/sidekiq-rate-limiter/server_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@

it 'should set Sidekiq.options[:fetch] as desired' do
Sidekiq.configure_server do |config|
if Sidekiq::VERSION =~ /^(4|5|6.0)/
if Sidekiq::VERSION =~ /^(4|5|6\.0)/
expect(Sidekiq.options[:fetch]).to eql(Sidekiq::RateLimiter::Fetch)
elsif Sidekiq::VERSION =~ /^7\./
expect(Sidekiq.default_configuration[:fetch_class]).to eq(Sidekiq::RateLimiter::Fetch)
else
expect(Sidekiq.options[:fetch]).to be_a(Sidekiq::RateLimiter::Fetch)
end
Expand All @@ -18,8 +20,10 @@

it 'should inherit from Sidekiq::BasicFetch' do
Sidekiq.configure_server do |config|
if Sidekiq::VERSION =~ /^(4|5|6.0)/
if Sidekiq::VERSION =~ /^(4|5|6\.0)/
expect(Sidekiq.options[:fetch]).to be < Sidekiq::BasicFetch
elsif Sidekiq::VERSION =~ /^7\./
expect(Sidekiq.default_configuration[:fetch_class]).to be < Sidekiq::BasicFetch
else
expect(Sidekiq.options[:fetch].class.ancestors[1]).to be(Sidekiq::BasicFetch)
end
Expand Down