Skip to content
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

Update task sample comments #2156

Merged
merged 3 commits into from
May 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 12 additions & 24 deletions tasks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,17 @@
[![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.

`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).
Expand All @@ -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:
Expand All @@ -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://<project_id>.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
Expand Down
4 changes: 2 additions & 2 deletions tasks/create_http_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -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://<project-id>.appspot.com/example_task_handler'
# url = 'https://example.com/task_handler'
# payload = 'hello'

# Construct the fully qualified queue name.
Expand Down
4 changes: 2 additions & 2 deletions tasks/create_http_task_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions tasks/create_http_task_with_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions tasks/create_http_task_with_token_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down