diff --git a/tasks/README.md b/tasks/README.md index 00503ccd3924..2c23e4824479 100644 --- a/tasks/README.md +++ b/tasks/README.md @@ -3,14 +3,10 @@ [![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. +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. @@ -18,12 +14,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). @@ -35,15 +25,13 @@ 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-app-engine-queue my-appengine-queue +gcloud beta tasks queues create my-queue ``` -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 +46,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=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-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,