From 324a2684f7e1da96c1b2e86866f602bc72c4cd57 Mon Sep 17 00:00:00 2001 From: averikitsch Date: Wed, 15 May 2019 08:55:23 -0700 Subject: [PATCH 1/3] Update task comments --- tasks/README.md | 30 ++++++----------------- tasks/create_http_task.py | 4 +-- tasks/create_http_task_test.py | 4 +-- tasks/create_http_task_with_token.py | 4 +-- tasks/create_http_task_with_token_test.py | 4 +-- 5 files changed, 16 insertions(+), 30 deletions(-) diff --git a/tasks/README.md b/tasks/README.md index 00503ccd3924..55910e4ad19b 100644 --- a/tasks/README.md +++ b/tasks/README.md @@ -3,14 +3,9 @@ [![Open in Cloud Shell][shell_img]][shell_link] [shell_img]: http://gstatic.com/cloudssh/images/open-btn.png -[shell_link]: https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/GoogleCloudPlatform/python-docs-samples&page=editor&open_in_editor=appengine/flexible/tasks/README.md +[shell_link]: https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/GoogleCloudPlatform/python-docs-samples&page=editor&open_in_editor=tasks/README.md -Sample command-line programs for interacting with the Cloud Tasks API -. - -App Engine queues push tasks to an App Engine HTTP target. This directory -contains both the App Engine app to deploy, as well as the snippets to run -locally to push tasks to it, which could also be called on App Engine. +Sample command-line programs for interacting with the Cloud Tasks API. `create_http_task.py` is a simple command-line program to create tasks to be pushed to an URL endpoint. @@ -18,12 +13,6 @@ tasks to be pushed to an URL endpoint. `create_http_task_with_token.py` is a simple command-line program to create tasks to be pushed to an URL endpoint with authorization header. -`main.py` is the main App Engine app. This app serves as an endpoint to receive -App Engine task attempts. - -`app.yaml` configures the App Engine app. - - ## Prerequisites to run locally: Please refer to [Setting Up a Python Development Environment](https://cloud.google.com/python/setup). @@ -38,12 +27,9 @@ To set up authentication, please refer to our To create a queue using the Cloud SDK, use the following gcloud command: ``` -gcloud beta tasks queues create-app-engine-queue my-appengine-queue +gcloud beta tasks queues create ``` -Note: A newly created queue will route to the default App Engine service and -version unless configured to do otherwise. - ## Run the Sample Using the Command Line Set environment variables: @@ -58,25 +44,25 @@ Then the queue ID, as specified at queue creation time. Queue IDs already created can be listed with `gcloud beta tasks queues list`. ``` -export QUEUE_ID=my-appengine-queue +export QUEUE_ID= ``` And finally the location ID, which can be discovered with `gcloud beta tasks queues describe $QUEUE_ID`, with the location embedded in the "name" value (for instance, if the name is -"projects/my-project/locations/us-central1/queues/my-appengine-queue", then the +"projects/my-project/locations/us-central1/queues/my-queue", then the location is "us-central1"). ``` export LOCATION_ID=us-central1 ``` -### Using HTTP Push Queues +### Creating Tasks with HTTP Targets Set an environment variable for the endpoint to your task handler. This is an -example url to send requests to the App Engine task handler: +example url: ``` -export URL=https://.appspot.com/example_task_handler +export URL=https://example.com/task_handler ``` Running the sample will create a task and send the task to the specific URL diff --git a/tasks/create_http_task.py b/tasks/create_http_task.py index 6ff3a6a2cfa6..eb1a446fc9d8 100644 --- a/tasks/create_http_task.py +++ b/tasks/create_http_task.py @@ -35,9 +35,9 @@ def create_http_task(project, # TODO(developer): Uncomment these lines and replace with your values. # project = 'my-project-id' - # queue = 'my-appengine-queue' + # queue = 'my-queue' # location = 'us-central1' - # url = 'https://.appspot.com/example_task_handler' + # url = 'https://example.com/task_handler' # payload = 'hello' # Construct the fully qualified queue name. diff --git a/tasks/create_http_task_test.py b/tasks/create_http_task_test.py index 6acfeaacbdb1..b1e50cc82dea 100644 --- a/tasks/create_http_task_test.py +++ b/tasks/create_http_task_test.py @@ -18,11 +18,11 @@ TEST_PROJECT_ID = os.getenv('GCLOUD_PROJECT') TEST_LOCATION = os.getenv('TEST_QUEUE_LOCATION', 'us-central1') -TEST_QUEUE_NAME = os.getenv('TEST_QUEUE_NAME', 'my-appengine-queue') +TEST_QUEUE_NAME = os.getenv('TEST_QUEUE_NAME', 'my-queue') def test_create_http_task(): - url = 'https://example.appspot.com/example_task_handler' + url = 'https://example.com/task_handler' result = create_http_task.create_http_task( TEST_PROJECT_ID, TEST_QUEUE_NAME, TEST_LOCATION, url) assert TEST_QUEUE_NAME in result.name diff --git a/tasks/create_http_task_with_token.py b/tasks/create_http_task_with_token.py index 1b79a9b3fc7d..665d0714384c 100644 --- a/tasks/create_http_task_with_token.py +++ b/tasks/create_http_task_with_token.py @@ -35,9 +35,9 @@ def create_http_task(project, # TODO(developer): Uncomment these lines and replace with your values. # project = 'my-project-id' - # queue = 'my-appengine-queue' + # queue = 'my-queue' # location = 'us-central1' - # url = 'https://example.com/example_task_handler' + # url = 'https://example.com/task_handler' # payload = 'hello' # Construct the fully qualified queue name. diff --git a/tasks/create_http_task_with_token_test.py b/tasks/create_http_task_with_token_test.py index 5b98c566e9e7..d95ceca33126 100644 --- a/tasks/create_http_task_with_token_test.py +++ b/tasks/create_http_task_with_token_test.py @@ -18,13 +18,13 @@ TEST_PROJECT_ID = os.getenv('GCLOUD_PROJECT') TEST_LOCATION = os.getenv('TEST_QUEUE_LOCATION', 'us-central1') -TEST_QUEUE_NAME = os.getenv('TEST_QUEUE_NAME', 'my-appengine-queue') +TEST_QUEUE_NAME = os.getenv('TEST_QUEUE_NAME', 'my-queue') TEST_SERVICE_ACCOUNT = ( 'test-run-invoker@python-docs-samples-tests.iam.gserviceaccount.com') def test_create_http_task_with_token(): - url = 'https://example.com/example_task_handler' + url = 'https://example.com/task_handler' result = create_http_task_with_token.create_http_task(TEST_PROJECT_ID, TEST_QUEUE_NAME, TEST_LOCATION, From 870202138e1575c582cde4dc2a9d664e92b8eff6 Mon Sep 17 00:00:00 2001 From: averikitsch Date: Wed, 15 May 2019 12:31:49 -0700 Subject: [PATCH 2/3] Update readme --- tasks/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tasks/README.md b/tasks/README.md index 55910e4ad19b..7c3dba4bda4f 100644 --- a/tasks/README.md +++ b/tasks/README.md @@ -5,7 +5,8 @@ [shell_img]: http://gstatic.com/cloudssh/images/open-btn.png [shell_link]: https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/GoogleCloudPlatform/python-docs-samples&page=editor&open_in_editor=tasks/README.md -Sample command-line programs for interacting with the Cloud Tasks API. +This sample demonstrates how to use the +[Cloud Tasks](https://cloud.google.com/tasks/docs/) client library. `create_http_task.py` is a simple command-line program to create tasks to be pushed to an URL endpoint. From 6325e2de6ab228864e247eaa944a97f19a360770 Mon Sep 17 00:00:00 2001 From: averikitsch Date: Wed, 15 May 2019 14:33:17 -0700 Subject: [PATCH 3/3] Update queue name --- tasks/README.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tasks/README.md b/tasks/README.md index 7c3dba4bda4f..2c23e4824479 100644 --- a/tasks/README.md +++ b/tasks/README.md @@ -25,10 +25,11 @@ To set up authentication, please refer to our ## Creating a queue -To create a queue using the Cloud SDK, use the following gcloud command: +To create a queue (named `my-queue`) using the Cloud SDK, use the following +gcloud command: ``` -gcloud beta tasks queues create +gcloud beta tasks queues create my-queue ``` ## Run the Sample Using the Command Line @@ -45,11 +46,11 @@ Then the queue ID, as specified at queue creation time. Queue IDs already created can be listed with `gcloud beta tasks queues list`. ``` -export QUEUE_ID= +export QUEUE_ID=my-queue ``` And finally the location ID, which can be discovered with -`gcloud beta tasks queues describe $QUEUE_ID`, with the location embedded in +`gcloud beta tasks queues describe my-queue`, with the location embedded in the "name" value (for instance, if the name is "projects/my-project/locations/us-central1/queues/my-queue", then the location is "us-central1").