Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion lib/shoryuken/queue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,11 @@ def send_message(options)
# @option options [Array<Hash>] :entries message entries to send
# @return [Aws::SQS::Types::SendMessageBatchResult] the batch send result
def send_messages(options)
client.send_message_batch(sanitize_messages!(options).merge(queue_url: url))
response = client.send_message_batch(sanitize_messages!(options).merge(queue_url: url))

log_failed_sends(response)

response
end

# Receives messages from the queue
Expand Down Expand Up @@ -120,6 +124,24 @@ def fifo?

private

# Logs any per-entry failures from a batch send. SQS reports these in
# response.failed (throttling, oversize/malformed entries, or a same-batch
# duplicate message_deduplication_id) rather than raising, so without this
# they are silently swallowed - notably by ShoryukenAdapter#enqueue_all,
# which reads only response.successful. Mirrors delete_messages.
#
# @param response [Aws::SQS::Types::SendMessageBatchResult] the batch result
# @return [void]
def log_failed_sends(response)
return unless response.respond_to?(:failed)

Array(response.failed).each do |failure|
logger.error do
"Could not send #{failure.id}, code: '#{failure.code}', message: '#{failure.message}', sender_fault: #{failure.sender_fault}"
end
end
end

# Initializes the FIFO attribute by calling fifo?
#
# @return [Boolean] whether the queue is FIFO
Expand Down
13 changes: 13 additions & 0 deletions spec/lib/shoryuken/queue_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,19 @@ def call(options)

subject.send_messages(%w[msg1 msg2])
end

context 'when some sends fail' do
it 'logs each failure (so bulk/enqueue_all drops are not silent)' do
failure = double(id: '1', code: 'code', message: '...', sender_fault: false)
logger = double('Logger')
allow(sqs).to receive(:send_message_batch).and_return(double(failed: [failure]))
allow(subject).to receive(:logger).and_return(logger)

expect(logger).to receive(:error)

subject.send_messages(entries: [{ id: '0', message_body: 'msg1' }])
end
end
end

describe '#fifo?' do
Expand Down