diff --git a/storage/cloud-client/README.rst b/storage/cloud-client/README.rst index f88c51766de..4d9e0a15227 100644 --- a/storage/cloud-client/README.rst +++ b/storage/cloud-client/README.rst @@ -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: diff --git a/storage/cloud-client/notification_polling.py b/storage/cloud-client/notification_polling.py index 0580eaea57d..73b921de4c0 100644 --- a/storage/cloud-client/notification_polling.py +++ b/storage/cloud-client/notification_polling.py @@ -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. 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. """ @@ -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)