Skip to content
Merged
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
11 changes: 4 additions & 7 deletions docs/pubsub_snippets.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,24 +311,21 @@ def subscription_pull(client, to_delete):
subscription.create()
to_delete.append(subscription)

# [START subscription_pull_none_pending]
pulled = subscription.pull(max_messages=1)
# [END subscription_pull_none_pending]
assert len(pulled) == 0

# [START subscription_pull_return_immediately]
pulled = subscription.pull(return_immediately=True)
# [END subscription_pull_return_immediately]

This comment was marked as spam.

This comment was marked as spam.

assert len(pulled) == 0
assert len(pulled) == 0, "unexpected message"

topic.publish(PAYLOAD1)
topic.publish(PAYLOAD2, extra=EXTRA)

time.sleep(1) # eventually-consistent

# [START subscription_pull]
pulled = subscription.pull(max_messages=2)
# [END subscription_pull]

assert len(pulled) == 2
assert len(pulled) == 2, "eventual consistency"

# [START subscription_modify_ack_deadline]
for ack_id, _ in pulled:
Expand Down
2 changes: 1 addition & 1 deletion gcloud/pubsub/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ def subscription_pull(self, subscription_path, return_immediately=False,
'maxMessages': max_messages,
}
response = conn.api_request(method='POST', path=path, data=data)
return response['receivedMessages']
return response.get('receivedMessages', ())

This comment was marked as spam.


def subscription_acknowledge(self, subscription_path, ack_ids):
"""API call: acknowledge retrieved messages for the subscription.
Expand Down