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

Cv2 4606 delete message #85

Merged
merged 2 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
CV2-4606 update routine to also delete messages when pushing incremen…
…ted-count messages
  • Loading branch information
DGaffney committed May 21, 2024
commit f6358a94f27e197d9eaef0767c636b36a7a96185
15 changes: 10 additions & 5 deletions lib/queue/queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,18 @@ def delete_messages_from_queue(self, queue: boto3.resources.base.ServiceResource
entries = []
for idx, message in enumerate(batch):
logger.debug(f"Deleting message: {message}")
entry = {
'Id': str(idx),
'ReceiptHandle': message.receipt_handle
}
entries.append(entry)
entries.append(self.delete_message_entry(message, idx))
queue.delete_messages(Entries=entries)

def delete_message_entry(message: schemas.Message, idx: int = 0) -> Dict[str, str]:
"""
Helper function to generate correct format of entry
"""
return {
'Id': str(idx),
'ReceiptHandle': message.receipt_handle
}

def receive_messages(self, batch_size: int = 1) -> List[Tuple[schemas.Message, boto3.resources.base.ServiceResource]]:
"""
Pull batch_size messages from input queue.
Expand Down
1 change: 1 addition & 0 deletions lib/queue/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,5 @@ def increment_message_error_counts(self, messages_with_queues: List[Tuple]):
else:
updated_message = schemas.parse_message(message_body)
updated_message.retry_count = retry_count
queue.delete_messages(Entries=[self.delete_message_entry(message)])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this isn't including the idx (which is mapped to the id) is it needed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep - idx is only needed as some unique identifier in a list of items - and on the other side of this, it just defaults to 0 if not passed along, so this works fine!

self.push_message(self.input_queue_name, updated_message)
Loading