Skip to content

Fix TypeError when running Storage notification polling exmaple. #1135

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 12 commits into from
Sep 22, 2017
49 changes: 33 additions & 16 deletions storage/cloud-client/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -225,26 +225,43 @@ To run this sample:

$ python notification_polling.py

usage: notification_polling.py [-h] subscription
usage: notification_polling.py [-h] project subscription

This application demonstrates how to poll for GCS notifications from a Cloud
Pub/Sub subscription, parse the incoming message, and acknowledge the
successful processing of the message. This application will work with any
subscription configured for pull rather than push notifications. If you do not
already have notifications configured, you may consult the docs at
This application demonstrates how to poll for GCS notifications from a
Cloud Pub/Sub subscription, parse the incoming message, and acknowledge the
successful processing of the message.

This application will work with any subscription configured for pull rather
than push notifications. If you do not already have notifications configured,
you may consult the docs at
https://cloud.google.com/storage/docs/reporting-changes or follow the steps
below: 1. Activate the Google Cloud Pub/Sub API, if you have not already done
so. https://console.cloud.google.com/flows/enableapi?apiid=pubsub 2. Create a
Google Cloud Storage bucket: $ gsutil mb gs://testbucket 3. Create a Cloud
Pub/Sub topic and publish bucket notifications there: $ gsutil notification
create -f json -t testtopic gs://testbucket 4. Create a subscription for your
new topic: $ gcloud beta pubsub subscriptions create testsubscription
--topic=testtopic 5. Run this program: $ python notification_polling
testsubscription 6. 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 in the app.
below:

1. First, follow the common setup steps for these snippets, specically
configuring auth and installing dependencies. See the README's "Setup"
section.

2. Activate the Google Cloud Pub/Sub API, if you have not already done so.
https://console.cloud.google.com/flows/enableapi?apiid=pubsub

3. Create a Google Cloud Storage bucket:
$ gsutil mb gs://testbucket

4. Create a Cloud Pub/Sub topic and publish bucket notifications there:
$ gsutil notification create -f json -t testtopic gs://testbucket

5. Create a subscription for your new topic:
$ gcloud beta pubsub subscriptions create testsubscription --topic=testtopic

6. Run this program:
$ python notification_polling 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
in the app.

positional arguments:
project The ID of the project that owns the subscription
subscription The ID of the Pub/Sub subscription

optional arguments:
Expand Down
26 changes: 17 additions & 9 deletions storage/cloud-client/notification_polling.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,26 @@
https://cloud.google.com/storage/docs/reporting-changes or follow the steps
below:

1. Activate the Google Cloud Pub/Sub API, if you have not already done so.
1. First, follow the common setup steps for these snippets, specically
configuring auth and installing dependencies. See the README's "Setup"
section.

2. Activate the Google Cloud Pub/Sub API, if you have not already done so.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you'll need to update all the numbers after this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, done.

https://console.cloud.google.com/flows/enableapi?apiid=pubsub

2. Create a Google Cloud Storage bucket:
3. Create a Google Cloud Storage bucket:
$ gsutil mb gs://testbucket

3. Create a Cloud Pub/Sub topic and publish bucket notifications there:
4. Create a Cloud Pub/Sub topic and publish bucket notifications there:
$ gsutil notification create -f json -t testtopic gs://testbucket

4. Create a subscription for your new topic:
5. Create a subscription for your new topic:
$ gcloud beta pubsub subscriptions create testsubscription --topic=testtopic

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

6. While the program is running, upload and delete some files in the testbucket
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
in the app.
"""
Expand Down Expand Up @@ -110,8 +114,12 @@ def callback(message):

if __name__ == '__main__':
parser = argparse.ArgumentParser(
description=__doc__)
description=__doc__,
formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument(
'project',
help='The ID of the project that owns the subscription')
parser.add_argument('subscription',
help='The ID of the Pub/Sub subscription')
args = parser.parse_args()
poll_notifications(args.subscription)
poll_notifications(args.project, args.subscription)