8000 Add support for overwrite attributes (#1142) · howinator/python-docs-samples@954b6fb · GitHub
[go: up one dir, main page]

Skip to content

Commit 954b6fb

Browse files
BrandonYJon Wayne Parrott
authored andcommitted
Add support for overwrite attributes (GoogleCloudPlatform#1142)
* Add support for overwrite attributes, bug fixes * Lint fix for overwrite line * Switch variable to snake_case
1 parent 1cc506e commit 954b6fb

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

storage/cloud-client/notification_polling.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
$ gcloud beta pubsub subscriptions create testsubscription --topic=testtopic
4242
4343
6. Run this program:
44-
$ python notification_polling my-project-id testsubscription
44+
$ python notification_polling.py my-project-id testsubscription
4545
4646
7. While the program is running, upload and delete some files in the testbucket
4747
bucket (you could use the console or gsutil) and watch as changes scroll by
@@ -64,6 +64,8 @@ def summarize(message):
6464
bucket_id = attributes['bucketId']
6565
object_id = attributes['objectId']
6666
generation = attributes['objectGeneration']
67+
overwrote_generation = attributes['overwroteGeneration']
68+
overwritten_by_generation = attributes['overwrittenByGeneration']
6769
description = (
6870
'\tEvent type: {event_type}\n'
6971
'\tBucket ID: {bucket_id}\n'
@@ -74,6 +76,12 @@ def summarize(message):
7476
object_id=object_id,
7577
generation=generation)
7678

79+
if overwrote_generation:
80+
description += '\tOverwrote generation: %s\n' % overwrote_generation
81+
if overwritten_by_generation:
82+
description += '\tOverwritten by generation: %s\n' % (
83+
overwritten_by_generation)
84+
7785
payload_format = attributes['payloadFormat']
7886
if payload_format == 'JSON_API_V1':
7987
object_metadata = json.loads(data)
@@ -99,7 +107,7 @@ def poll_notifications(project, subscription_name):
99107
project, subscription_name)
100108

101109
def callback(message):
102-
print('Received message:\n{1}'.format(summarize(message)))
110+
print('Received message:\n{}'.format(summarize(message)))
103111
message.ack()
104112

105113
subscriber.subscribe(subscription_path, callback=callback)

0 commit comments

Comments
 (0)
0