10000 [Cloud Tasks] Move samples to new folder (#2114) · lisabang/python-docs-samples@e85f93f · GitHub
[go: up one dir, main page]

Skip to content

Commit e85f93f

Browse files
authored
[Cloud Tasks] Move samples to new folder (GoogleCloudPlatform#2114)
* Move samples to keep consistent with other langauges * Ad system tests as well
1 parent 8d0d072 commit e85f93f

File tree

6 files changed

+146
-2
lines changed

6 files changed

+146
-2
lines changed

.kokoro/presubmit_tests_tasks.cfg

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Format: //devtools/kokoro/config/proto/build.proto
2+
3+
# Download secrets from Cloud Storage.
4+
gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/python-docs-samples"
5+
6+
# Tell the trampoline which build file to use.
7+
env_vars: {
8+
key: "TRAMPOLINE_BUILD_FILE"
9+
value: "github/python-docs-samples/.kokoro/system_tests.sh"
10+
}
11+
12+
env_vars: {
13+
key: "NOX_SESSION"
14+
value: "tasks and py36 and not appengine"
15+
}

.kokoro/system_tests_tasks.cfg

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Format: //devtools/kokoro/config/proto/build.proto
2+
3+
# Download secrets from Cloud Storage.
4+
gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/python-docs-samples"
5+
6+
# Tell the trampoline which build file to use.
7+
env_vars: {
8+
key: "TRAMPOLINE_BUILD_FILE"
9+
value: "github/python-docs-samples/.kokoro/system_tests.sh"
10+
}
11+
12+
env_vars: {
13+
key: "NOX_SESSION"
14+
value: "tasks and py36 and not appengine"
15+
}

tasks/README.md

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# Google Cloud Tasks Samples
2+
3+
[![Open in Cloud Shell][shell_img]][shell_link]
4+
5+
[shell_img]: http://gstatic.com/cloudssh/images/open-btn.png
6+
[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
7+
8+
Sample command-line programs for interacting with the Cloud Tasks API
9+
.
10+
11+
App Engine queues push tasks to an App Engine HTTP target. This directory
12+
contains both the App Engine app to deploy, as well as the snippets to run
13+
locally to push tasks to it, which could also be called on App Engine.
14+
15+
`create_app_engine_queue_task.py` is a simple command-line program to create
16+
tasks to be pushed to the App Engine app.
17+
18+
`main.py` is the main App Engine app. This app serves as an endpoint to receive
19+
App Engine task attempts.
20+
21+
`app.yaml` configures the App Engine app.
22+
23+
24+
## Prerequisites to run locally:
25+
26+
Please refer to [Setting Up a Python Development Environment](https://cloud.google.com/python/setup).
27+
28+
## Authentication
29+
30+
To set up authentication, please refer to our
31+
[authentication getting started guide](https://cloud.google.com/docs/authentication/getting-started).
32+
33+
## Creating a queue
34+
35+
To create a queue using the Cloud SDK, use the following gcloud command:
36+
37+
```
38+
gcloud beta tasks queues create-app-engine-queue my-appengine-queue
39+
```
40+
41+
Note: A newly created queue will route to the default App Engine service and
42+
version unless configured to do otherwise.
43+
44+
## Deploying the App Engine App
45+
46+
Deploy the App Engine app with gcloud:
47+
48+
* To deploy to the Standard environment:
49+
```
50+
gcloud app deploy app.yaml
51+
```
52+
* To deploy to the Flexible environment:
53+
```
54+
gcloud app deploy app.flexible.yaml
55+
```
56+
57+
Verify the index page is serving:
58+
59+
```
60+
gcloud app browse
61+
```
62+
63+
The App Engine app serves as a target for the push requests. It has an
64+
endpoint `/example_task_handler` that reads the payload (i.e., the request body)
65+
of the HTTP POST request and logs it. The log output can be viewed with:
66+
67+
```
68+
gcloud app logs read
69+
```
70+
71+
## Run the Sample Using the Command Line
72+
73+
Set environment variables:
74+
75+
First, your project ID:
76+
77+
```
78+
export PROJECT_ID=my-project-id
79+
```
80+
81+
Then the queue ID, as specified at queue creation time. Queue IDs already
82+
created can be listed with `gcloud beta tasks queues list`.
83+
84+
```
85+
export QUEUE_ID=my-appengine-queue
86+
```
87+
88+
And finally the location ID, which can be discovered with
89+
`gcloud beta tasks queues describe $QUEUE_ID`, with the location embedded in
90+
the "name" value (for instance, if the name is
91+
"projects/my-project/locations/us-central1/queues/my-appengine-queue", then the
92+
location is "us-central1").
93+
94+
```
95+
export LOCATION_ID=us-central1
96+
```
97+
98+
### Using HTTP Push Queues
99+
100+
Set an environment variable for the endpoint to your task handler. This is an
101+
example url to send requests to the App Engine task handler:
102+
```
103+
export URL=https://<project_id>.appspot.com/example_task_handler
104+
```
105+
106+
Running the sample will create a task and send the task to the specific URL
107+
endpoint, with a payload specified:
108+
109+
```
110+
python create_http_task.py --project=$PROJECT_ID --queue=$QUEUE_ID --location=$LOCATION_ID --url=$URL --payload=hello
111+
```

appengine/flexible/tasks/create_http_task_test.py renamed to tasks/create_http_task_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
TEST_QUEUE_NAME = os.getenv('TEST_QUEUE_NAME', 'my-appengine-queue')
2222

2323

24-
def test_create_task():
25-
url = 'https://' + TEST_PROJECT_ID + '.appspot.com/example_task_handler'
24+
def test_create_http_task():
25+
url = 'https://example.appspot.com/example_task_handler'
2626
result = create_http_task.create_http_task(
2727
TEST_PROJECT_ID, TEST_QUEUE_NAME, TEST_LOCATION, url)
2828
assert TEST_QUEUE_NAME in result.name

tasks/requirements.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Flask==1.0.2
2+
gunicorn==19.9.0
3+
google-cloud-tasks==0.6.0

0 commit comments

Comments
 (0)
0