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

samples: handle empty response in sync pull samples #586

Merged
merged 1 commit into from Feb 15, 2022
Merged
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
6 changes: 6 additions & 0 deletions samples/snippets/subscriber.py
Expand Up @@ -605,6 +605,9 @@ def synchronous_pull(project_id: str, subscription_id: str) -> None:
retry=retry.Retry(deadline=300),
)

if len(response.received_messages) == 0:
return

ack_ids = []
for received_message in response.received_messages:
print(f"Received: {received_message.message.data}.")
Expand Down Expand Up @@ -651,6 +654,9 @@ def synchronous_pull_with_lease_management(
retry=retry.Retry(deadline=300),
)

if len(response.received_messages) == 0:
return

# Start a process for each message based on its size modulo 10.
for message in response.received_messages:
process = multiprocessing.Process(
Expand Down