Skip to content

Commit

Permalink
Fix bug where empty queues were not paused in batch processing mode (f…
Browse files Browse the repository at this point in the history
…ixes #568)
  • Loading branch information
snoopie committed Jun 18, 2019
1 parent 7c33d24 commit b92dd40
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/shoryuken/manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ def assign(queue_name, sqs_msg)
end

def dispatch_batch(queue)
return if (batch = @fetcher.fetch(queue, BATCH_LIMIT)).none?
batch = @fetcher.fetch(queue, BATCH_LIMIT)
@polling_strategy.messages_found(queue.name, batch.size)
assign(queue.name, patch_batch!(batch))
assign(queue.name, patch_batch!(batch)) if batch.any?
end

def dispatch_single_messages(queue)
Expand Down
15 changes: 15 additions & 0 deletions spec/shoryuken/manager_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,21 @@

subject.send(:dispatch)
end

context "and there are no messages in the queue" do
specify do
messages = %w[]
q = Shoryuken::Polling::QueueConfiguration.new(queue, {})

expect(fetcher).to receive(:fetch).with(q, described_class::BATCH_LIMIT).and_return(messages)
expect(subject).to receive(:fire_event).with(:dispatch, false, queue_name: q.name)
allow(subject).to receive(:batched_queue?).with(q).and_return(true)
expect(polling_strategy).to receive(:messages_found).with(q.name, 0)
expect_any_instance_of(described_class).to receive(:assign).never

subject.send(:dispatch)
end
end
end
end

Expand Down

0 comments on commit b92dd40

Please sign in to comment.