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 empty_queue_fetch_delay bug in batch processing mode #569

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