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

Fix bulk requeue compatibility issue #1

Merged
merged 1 commit into from
Aug 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/sidekiq/limit_fetch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ def retrieve_work
end

def bulk_requeue(*args)
Sidekiq::BasicFetch.bulk_requeue(*args)
klass = Sidekiq::BasicFetch
fetch = klass.respond_to?(:bulk_requeue) ? klass : klass.new(Sidekiq::options)
fetch.bulk_requeue(*args)
end

def redis_retryable
Expand Down
30 changes: 27 additions & 3 deletions spec/sidekiq/limit_fetch_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,20 @@
let(:limits) {{ 'queue1' => 1, 'queue2' => 2 }}

before do
subject::Queues.start options
subject::Queues.start options

Sidekiq.redis do |it|
it.del 'queue:queue1'
it.lpush 'queue:queue1', 'task1'
it.lpush 'queue:queue1', 'task2'
it.del 'queue:queue2'
it.expire 'queue:queue1', 30
end
end

it 'should acquire lock on queue for execution' do
Sidekiq.redis do |it|
it.lpush 'queue:queue1', 'task1'
it.lpush 'queue:queue1', 'task2'
end
work = subject.retrieve_work
expect(work.queue_name).to eq 'queue1'
expect(work.job).to eq 'task1'
Expand Down Expand Up @@ -45,4 +48,25 @@
work = subject.retrieve_work
expect(work.job).to eq 'task2'
end

it 'bulk requeues' do

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is quite the test.

Sidekiq.redis do |it|
it.lpush 'queue:queue1', 'task1'
it.lpush 'queue:queue2', 'task2'
it.lpush 'queue:queue2', 'task3'
end
q1 = Sidekiq::Queue['queue1']
q2 = Sidekiq::Queue['queue2']
expect(q1.size).to eq 1
expect(q2.size).to eq 2

fetch = subject.new(queues: ['queue1', 'queue2'])
works = 3.times.map { fetch.retrieve_work }
expect(q1.size).to eq 0
expect(q2.size).to eq 0

fetch.bulk_requeue(works, queues: [])
expect(q1.size).to eq 1
expect(q2.size).to eq 2
end
end