8000 Add support for overwrite attributes by BrandonY · Pull Request #1142 · GoogleCloudPlatform/python-docs-samples · GitHub
[go: up one dir, main page]

Skip to content

Add support for overwrite attributes #1142

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

Merged
merged 3 commits into from
Sep 27, 2017
Merged
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
12 changes: 10 additions & 2 deletions storage/cloud-client/notification_polling.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
$ gcloud beta pubsub subscriptions create testsubscription --topic=testtopic

6. Run this program:
$ python notification_polling my-project-id testsubscription
$ python notification_polling.py my-project-id testsubscription

7. While the program is running, upload and delete some files in the testbucket
bucket (you could use the console or gsutil) and watch as changes scroll by
Expand All @@ -64,6 +64,8 @@ def summarize(message):
bucket_id = attributes['bucketId']
object_id = attributes['objectId']
generation = attributes['objectGeneration']
overwrote_generation = attributes['overwroteGeneration']
overwritten_by_generation = attributes['overwrittenByGeneration']
description = (
'\tEvent type: {event_type}\n'
'\tBucket ID: {bucket_id}\n'
Expand All @@ -74,6 +76,12 @@ def summarize(message):
object_id=object_id,
generation=generation)

if overwrote_generation:
description += '\tOverwrote generation: %s\n' % overwrote_generation
if overwritten_by_generation:
description += '\tOverwritten by generation: %s\n' % (
overwritten_by_generation)

payload_format = attributes['payloadFormat']
if payload_format == 'JSON_API_V1':
object_metadata = json.loads(data)
Expand All @@ -99,7 +107,7 @@ def poll_notifications(project, subscription_name):
project, subscription_name)

def callback(message):
print('Received message:\n{1}'.format(summarize(message)))
print('Received message:\n{}'.format(summarize(message)))
message.ack()

subscriber.subscribe(subscription_path, callback=callback)
Expand Down
0