Skip to content

Commit

Permalink
A refactoring in the internal Fetch API was introduced in Sidekiq 6.1…
Browse files Browse the repository at this point in the history
….0 that is not backwards compatible.

As part of this refactoring the object in the :fetch option is expected
to be an instance of Sidekiq::BasicFetch or an object that responds to
the same methods.

This change allows using the gem with newer versions while keeping
compatibility with old ones. See sidekiq/sidekiq#4602 for more details.
  • Loading branch information
anero committed Oct 7, 2020
1 parent 3e8bc81 commit 391f00c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 6 additions & 1 deletion lib/sidekiq-rate-limiter/server.rb
Expand Up @@ -2,5 +2,10 @@
require 'sidekiq-rate-limiter/fetch'

Sidekiq.configure_server do |config|
Sidekiq.options[:fetch] = Sidekiq::RateLimiter::Fetch
# Backwards compatibility for Sidekiq < 6.1.0 (see https://github.com/mperham/sidekiq/pull/4602 for details)
if (Sidekiq::BasicFetch.respond_to?(:bulk_requeue))
Sidekiq.options[:fetch] = Sidekiq::RateLimiter::Fetch
else
Sidekiq.options[:fetch] = Sidekiq::RateLimiter::Fetch.new(Sidekiq.options)
end
end
4 changes: 2 additions & 2 deletions spec/sidekiq-rate-limiter/server_spec.rb
Expand Up @@ -8,13 +8,13 @@

it 'should set Sidekiq.options[:fetch] as desired' do
Sidekiq.configure_server do |config|
expect(Sidekiq.options[:fetch]).to eql(Sidekiq::RateLimiter::Fetch)
expect(Sidekiq.options[:fetch]).to be_an_instance_of(Sidekiq::RateLimiter::Fetch)
end
end

it 'should inherit from Sidekiq::BasicFetch' do
Sidekiq.configure_server do |config|
expect(Sidekiq.options[:fetch]).to be < Sidekiq::BasicFetch
expect(Sidekiq.options[:fetch].class).to be < Sidekiq::BasicFetch
end
end
end

0 comments on commit 391f00c

Please sign in to comment.