Skip to content
This repository was archived by the owner on Feb 1, 2024. It is now read-only.

Commit 5eb727a

Browse files
authored
Update Cloud Tasks Push Queue Sample [(#1698)](GoogleCloudPlatform/python-docs-samples#1698)
* deleted pull queues * updated samples * fix dependency versions
1 parent bbd352f commit 5eb727a

File tree

3 files changed

+22
-15
lines changed

3 files changed

+22
-15
lines changed

samples/appengine/flexible/tasks/README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ gcloud beta tasks queues create-app-engine-queue my-appengine-queue
4141
Note: A newly created queue will route to the default App Engine service and
4242
version unless configured to do otherwise.
4343

44-
## Deploying the App Engine app
44+
## Deploying the App Engine App
4545

4646
Deploy the App Engine app with gcloud:
4747

@@ -56,14 +56,14 @@ gcloud app browse
5656
```
5757

5858
The App Engine app serves as a target for the push requests. It has an
59-
endpoint `/log_payload` that reads the payload (i.e., the request body) of the
60-
HTTP POST request and logs it. The log output can be viewed with:
59+
endpoint `/example_task_handler` that reads the payload (i.e., the request body)
60+
of the HTTP POST request and logs it. The log output can be viewed with:
6161

6262
```
6363
gcloud app logs read
6464
```
6565

66-
## Running the Samples
66+
## Run the Sample Using the Command Line
6767

6868
Set environment variables:
6969

@@ -90,7 +90,8 @@ location is "us-central1").
9090
export LOCATION_ID=us-central1
9191
```
9292

93-
Create a task, targeted at the `log_payload` endpoint, with a payload specified:
93+
Running the sample will create a task, targeted at the 'example_task_handler'
94+
endpoint, with a payload specified:
9495

9596
```
9697
python create_app_engine_queue_task.py --project=$PROJECT_ID --queue=$QUEUE_ID --location=$LOCATION_ID --payload=hello

samples/appengine/flexible/tasks/create_app_engine_queue_task.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,29 +18,38 @@
1818
import datetime
1919

2020

21-
# [START cloud_tasks_appengine_create_task]
2221
def create_task(project, queue, location, payload=None, in_seconds=None):
22+
# [START cloud_tasks_appengine_create_task]
2323
"""Create a task for a given queue with an arbitrary payload."""
2424

25-
from google.cloud import tasks_v2beta2
25+
from google.cloud import tasks_v2beta3
2626
from google.protobuf import timestamp_pb2
2727

2828
# Create a client.
29-
client = tasks_v2beta2.CloudTasksClient()
29+
client = tasks_v2beta3.CloudTasksClient()
30+
31+
# TODO(developer): Uncomment these lines and replace with your values.
32+
# project = 'my-project-id'
33+
# queue = 'my-appengine-queue'
34+
# location = 'us-central1'
35+
# payload = 'hello'
36+
37+
# Construct the fully qualified queue name.
38+
parent = client.queue_path(project, location, queue)
3039

3140
# Construct the request body.
3241
task = {
3342
'app_engine_http_request': { # Specify the type of request.
3443
'http_method': 'POST',
35-
'relative_url': '/example_task_handler'
44+
'relative_uri': '/example_task_handler'
3645
}
3746
}
3847
if payload is not None:
3948
# The API expects a payload of type bytes.
4049
converted_payload = payload.encode()
4150

4251
# Add the payload to the request.
43-
task['app_engine_http_request']['payload'] = converted_payload
52+
task['app_engine_http_request']['body'] = converted_payload
4453

4554
if in_seconds is not None:
4655
# Convert "seconds from now" into an rfc3339 datetime string.
@@ -50,12 +59,9 @@ def create_task(project, queue, location, payload=None, in_seconds=None):
5059
timestamp = timestamp_pb2.Timestamp()
5160
timestamp.FromDatetime(d)
5261

53-
# Add the rfc3339 datetime string to the request.
62+
# Add the timestamp to the tasks.
5463
task['schedule_time'] = timestamp
5564

56-
# Construct the fully qualified queue name.
57-
parent = client.queue_path(project, location, queue)
58-
5965
# Use the client to build and send the task.
6066
response = client.create_task(parent, task)
6167

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
Flask==1.0.2
22
gunicorn==19.9.0
3-
google-cloud-tasks==0.2.0
3+
google-cloud-tasks==0.3.0

0 commit comments

Comments
 (0)