41
41
$ gcloud beta pubsub subscriptions create testsubscription --topic=testtopic
42
42
43
43
6. Run this program:
44
- $ python notification_polling my-project-id testsubscription
44
+ $ python notification_polling.py my-project-id testsubscription
45
45
46
46
7. While the program is running, upload and delete some files in the testbucket
47
47
bucket (you could use the console or gsutil) and watch as changes scroll by
@@ -64,6 +64,8 @@ def summarize(message):
64
64
bucket_id = attributes ['bucketId' ]
65
65
object_id = attributes ['objectId' ]
66
66
generation = attributes ['objectGeneration' ]
67
+ overwrote_generation = attributes ['overwroteGeneration' ]
68
+ overwritten_by_generation = attributes ['overwrittenByGeneration' ]
67
69
description = (
68
70
'\t Event type: {event_type}\n '
69
71
'\t Bucket ID: {bucket_id}\n '
@@ -74,6 +76,12 @@ def summarize(message):
74
76
object_id = object_id ,
75
77
generation = generation )
76
78
79
+ if overwrote_generation :
80
+ description += '\t Overwrote generation: %s\n ' % overwrote_generation
81
+ if overwritten_by_generation :
82
+ description += '\t Overwritten by generation: %s\n ' % (
83
+ overwritten_by_generation )
84
+
77
85
payload_format = attributes ['payloadFormat' ]
78
86
if payload_format == 'JSON_API_V1' :
79
87
object_metadata = json .loads (data )
@@ -99,7 +107,7 @@ def poll_notifications(project, subscription_name):
99
107
project , subscription_name )
100
108
101
109
def callback (message ):
102
- print ('Received message:\n {1 }' .format (summarize (message )))
110
+ print ('Received message:\n {}' .format (summarize (message )))
103
111
message .ack ()
104
112
105
113
subscriber .subscribe (subscription_path , callback = callback )
0 commit comments