Skip to content

Commit

Permalink
Made minor updates
Browse files Browse the repository at this point in the history
  • Loading branch information
jterapin committed Sep 28, 2023
1 parent cc0bb19 commit 0d3fd85
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions gems/aws-sdk-sqs/lib/aws-sdk-sqs/queue_poller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,11 @@ def check_idle_timeout(config, stats)
def process_messages(config, stats, messages, &block)
stats.received_message_count += messages.count
stats.last_message_received_at = Time.now
messages = dedupe_messages(messages)

# duplicated messages will have a different receipt handle
# so we need to provide the most recent receipt to
# delete a batch - thus, filtering below by message_id
messages = messages.reverse.uniq(&:message_id).reverse!
catch(:skip_delete) do
yield_messages(config, messages, stats, &block)
delete_messages(messages) unless config.skip_delete
Expand All @@ -418,16 +422,6 @@ def yield_messages(config, messages, stats, &block)
end
end

def dedupe_messages(messages)
# duplicate messages will have a different receipt handle
# so must provide the most recently receipt handle
# when deleting the message
messages.each_with_object({}) do |msg, unique|
unique[msg.message_id] = msg
unique
end.values
end

# Statistics tracked client-side by the {QueuePoller}.
class PollerStats
def initialize
Expand Down

0 comments on commit 0d3fd85

Please sign in to comment.