Skip to content

Commit

Permalink
Merge pull request #1 from optimumenergyco/bulk_requeue
Browse files Browse the repository at this point in the history
Fix bulk requeue compatibility issue
  • Loading branch information
optijon committed Aug 13, 2020
2 parents 1207ba9 + afd7106 commit 67e1810
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
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
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

0 comments on commit 67e1810

Please sign in to comment.