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 breaking change in bulk_requeue #111

Closed
wants to merge 3 commits into from
Closed
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
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
28 changes: 26 additions & 2 deletions spec/sidekiq/limit_fetch_spec.rb
Expand Up @@ -10,13 +10,16 @@

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
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