8000 Fix TypeError when running Storage notification polling exmaple. (#1135) · johnmanong/python-docs-samples@b94b7f4 · GitHub
[go: up one dir, main page]

Skip to content

Commit b94b7f4

Browse files
BrandonYJon Wayne Parrott
authored andcommitted
Fix TypeError when running Storage notification polling exmaple. (GoogleCloudPlatform#1135)
* Adds storage Pub/Sub notification polling tutorial * Fix formatting and add some tests * Auto-generate README * Simplify implementation, remove classes * Simplified example, removed de-duping * regenerate README * Remove explicit project parameter. * Fix notification TypeError on start. * Fix linter error. * Fix ordered list ordinals. * Rerun nox readmegen.
1 parent b9e2401 commit b94b7f4

File tree

2 files changed

+50
-25
lines changed

2 files changed

+50
-25
lines changed

storage/cloud-client/README.rst

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -225,26 +225,43 @@ To run this sample:
225225
226226
$ python notification_polling.py
227227
228-
usage: notification_polling.py [-h] subscription
228+
usage: notification_polling.py [-h] project subscription
229229
230-
This application demonstrates how to poll for GCS notifications from a Cloud
231-
Pub/Sub subscription, parse the incoming message, and acknowledge the
232-
successful processing of the message. This application will work with any
233-
subscription configured for pull rather than push notifications. If you do not
234-
already have notifications configured, you may consult the docs at
230+
This application demonstrates how to poll for GCS notifications from a
231+
Cloud Pub/Sub subscription, parse the incoming message, and acknowledge the
232+
successful processing of the message.
233+
234+
This application will work with any subscription configured for pull rather
235+
than push notifications. If you do not already have notifications configured,
236+
you may consult the docs at
235237
https://cloud.google.com/storage/docs/reporting-changes or follow the steps
236-
below: 1. Activate the Google Cloud Pub/Sub API, if you have not already done
237-
so. https://console.cloud.google.com/flows/enableapi?apiid=pubsub 2. Create a
238-
Google Cloud Storage bucket: $ gsutil mb gs://testbucket 3. Create a Cloud
239-
Pub/Sub topic and publish bucket notifications there: $ gsutil notification
240-
create -f json -t testtopic gs://testbucket 4. Create a subscription for your
241-
new topic: $ gcloud beta pubsub subscriptions create testsubscription
242-
--topic=testtopic 5. Run this program: $ python notification_polling
243-
testsubscription 6. While the program is running, upload and delete some files
244-
in the testbucket bucket (you could use the console or gsutil) and watch as
245-
changes scroll by in the app.
238+
below:
239+
240+
1. First, follow the common setup steps for these snippets, specically
241+
configuring auth and installing dependencies. See the README's "Setup"
242+
section.
243+
244+
2. Activate the Google Cloud Pub/Sub API, if you have not already done so.
245+
https://console.cloud.google.com/flows/enableapi?apiid=pubsub
246+
247+
3. Create a Google Cloud Storage bucket:
248+
$ gsutil mb gs://testbucket
249+
250+
4. Create a Cloud Pub/Sub topic and publish bucket notifications there:
251+
$ gsutil notification create -f json -t testtopic gs://testbucket
252+
253+
5. Create a subscription for your new topic:
254+
$ gcloud beta pubsub subscriptions create testsubscription --topic=testtopic
255+
256+
6. Run this program:
257+
$ python notification_polling my-project-id testsubscription
258+
259+
7. While the program is running, upload and delete some files in the testbucket
260+
bucket (you could use the console or gsutil) and watch as changes scroll by
261+
in the app.
246262
247263
positional arguments:
264+
project The ID of the project that owns the subscription
248265
subscription The ID of the Pub/Sub subscription
249266
250267
optional arguments:

storage/cloud-client/notification_polling.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,26 @@
2424
https://cloud.google.com/storage/docs/reporting-changes or follow the steps
2525
below:
2626
27-
1. Activate the Google Cloud Pub/Sub API, if you have not already done so.
27+
1. First, follow the common setup steps for these snippets, specically
28+
configuring auth and installing dependencies. See the README's "Setup"
29+
section.
30+
31+
2. Activate the Google Cloud Pub/Sub API, if you have not already done so.
2832
https://console.cloud.google.com/flows/enableapi?apiid=pubsub
2933
30-
2. Create a Google Cloud Storage bucket:
34+
3. Create a Google Cloud Storage bucket:
3135
$ gsutil mb gs://testbucket
3236
33-
3. Create a Cloud Pub/Sub topic and publish bucket notifications there:
37+
4. Create a Cloud Pub/Sub topic and publish bucket notifications there:
3438
$ gsutil notification create -f json -t testtopic gs://testbucket
3539
36-
4. Create a subscription for your new topic:
40+
5. Create a subscription for your new topic:
3741
$ gcloud beta pubsub subscriptions create testsubscription --topic=testtopic
3842
39-
5. Run this program:
40-
$ python notification_polling testsubscription
43+
6. Run this program:
44+
$ python notification_polling my-project-id testsubscription
4145
42-
6. While the program is running, upload and delete some files in the testbucket
46+
7. While the program is running, upload and delete some files in the testbucket
4347
bucket (you could use the console or gsutil) and watch as changes scroll by
4448
in the app.
4549
"""
@@ -110,8 +114,12 @@ def callback(message):
110114

111115
if __name__ == '__main__':
112116
parser = argparse.ArgumentParser(
113-
description=__doc__)
117+
description=__doc__,
118+
formatter_class=argparse.RawDescriptionHelpFormatter)
119+
parser.add_argument(
120+
'project',
121+
help='The ID of the project that owns the subscription')
114122
parser.add_argument('subscription',
115123
help='The ID of the Pub/Sub subscription')
116124
args = parser.parse_args()
117-
poll_notifications(args.subscription)
125+
poll_notifications(args.project, args.subscription)

0 commit comments

Comments
 (0)
0