Repository navigation
Conversation
Consuming leased messages from RECEIVE_<Queue> and acknowledging active leases via batch.ack lacked a runnable Python worker sample.
|
Here is the summary of changes. You are about to add 1 region tag.
This comment is generated by snippet-bot.
|
There was a problem hiding this comment.
Code Review
This pull request introduces functionality to receive and acknowledge messages from a Cloud Spanner queue, specifically querying the RECEIVE_UserTasks table-valued function, validating lease expirations, and acknowledging valid messages. It also includes comprehensive unit and integration tests. The review feedback recommends optimizing the message acknowledgement loop by wrapping it in a single database.batch() context manager to batch all acknowledgements into a single transaction rather than committing them individually.
| for key in valid_keys: | ||
| with database.batch() as batch: | ||
| batch.ack(queue=queue_name, key=key, ignore_not_found=True) | ||
| acked_count += 1 |
There was a problem hiding this comment.
Creating a new database.batch() context manager inside the loop commits each acknowledgement individually, resulting in multiple network roundtrips. Instead, you should wrap the loop inside a single database.batch() block to batch all acknowledgements into a single transaction/commit. Additionally, checking if valid_keys is not empty before entering the batch context prevents an unnecessary empty commit.
| for key in valid_keys: | |
| with database.batch() as batch: | |
| batch.ack(queue=queue_name, key=key, ignore_not_found=True) | |
| acked_count += 1 | |
| if valid_keys: | |
| with database.batch() as batch: | |
| for key in valid_keys: | |
| batch.ack(queue=queue_name, key=key, ignore_not_found=True) | |
| acked_count += 1 |
There was a problem hiding this comment.
Thanks! This comment refers to an earlier revision of this file; the code here has since been reworked in later commits, so this thread no longer applies to the current diff.
…roject_id Commits all valid message acknowledgements in a single batch Commit RPC and omits project identifiers from stdout and stderr.
Description
Consuming messages from a Cloud Spanner Queue requires streaming from
RECEIVE_<Queue>under a strong snapshot, verifyingSpannerLeaseExpirationTimestamp, and acknowledging processed keys viabatch.ack.Adds
spanner_queue_receive_messages.Checklist
Testing
Compliance & Style
spanner/, which the default repository owners cover.Post-Approval Actions