Skip to content

Commit 1e56320

Browse files
averikitschgcf-owl-bot[bot]engelke
authored
chore: update samples (#207)
* chore: update samples * 🦉 Updates from OwlBot See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * Update create_http_task_test.py Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com> Co-authored-by: Charles Engelke <[email protected]>
1 parent 4b4614b commit 1e56320

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

cloud-tasks/snippets/create_http_task.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,20 @@
1818

1919

2020
def create_http_task(
21-
project, queue, location, url, payload=None, in_seconds=None, task_name=None
21+
project,
22+
queue,
23+
location,
24+
url,
25+
payload=None,
26+
in_seconds=None,
27+
task_name=None,
28+
deadline=None,
2229
):
2330
# [START cloud_tasks_create_http_task]
2431
"""Create a task for a given queue with an arbitrary payload."""
2532

2633
from google.cloud import tasks_v2
27-
from google.protobuf import timestamp_pb2
34+
from google.protobuf import timestamp_pb2, duration_pb2
2835
import datetime
2936
import json
3037

@@ -39,6 +46,7 @@ def create_http_task(
3946
# payload = 'hello' or {'param': 'value'} for application/json
4047
# in_seconds = 180
4148
# task_name = 'my-unique-task'
49+
# deadline = 900
4250

4351
# Construct the fully qualified queue name.
4452
parent = client.queue_path(project, location, queue)
@@ -78,6 +86,11 @@ def create_http_task(
7886
# Add the name to tasks.
7987
task["name"] = client.task_path(project, location, queue, task_name)
8088

89+
if deadline is not None:
90+
# Add dispatch deadline for requests sent to the worker.
91+
duration = duration_pb2.Duration()
92+
task["dispatch_deadline"] = duration.FromSeconds(deadline)
93+
8194
# Use the client to build and send the task.
8295
response = client.create_task(request={"parent": parent, "task": task})
8396

cloud-tasks/snippets/create_http_task_test.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,15 @@ def test_create_http_task(test_queue):
4646
TEST_PROJECT_ID, TEST_QUEUE_NAME, TEST_LOCATION, url
4747
)
4848
assert TEST_QUEUE_NAME in result.name
49+
50+
result = create_http_task.create_http_task(
51+
TEST_PROJECT_ID,
52+
TEST_QUEUE_NAME,
53+
TEST_LOCATION,
54+
url,
55+
payload="hello",
56+
in_seconds=180,
57+
task_name=uuid.uuid4().hex,
58+
deadline=900,
59+
)
60+
assert TEST_QUEUE_NAME in result.name

0 commit comments

Comments
 (0)