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

fix: Update sample comments #58

Merged
merged 2 commits into from Dec 22, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions samples/snippets/create_http_task.py
Expand Up @@ -37,6 +37,8 @@ def create_http_task(
# location = 'us-central1'
# url = 'https://example.com/task_handler'
# payload = 'hello' or {'param': 'value'} for application/json
# in_seconds = 180
# task_name = 'my-unique-task'

# Construct the fully qualified queue name.
parent = client.queue_path(project, location, queue)
Expand Down
20 changes: 0 additions & 20 deletions samples/snippets/create_http_task_with_token.py
Expand Up @@ -14,8 +14,6 @@

from __future__ import print_function

import datetime


def create_http_task(
project,
Expand All @@ -24,14 +22,11 @@ def create_http_task(
url,
service_account_email,
payload=None,
in_seconds=None,
task_name=None,
):
# [START cloud_tasks_create_http_task_with_token]
"""Create a task for a given queue with an arbitrary payload."""

from google.cloud import tasks_v2
from google.protobuf import timestamp_pb2

# Create a client.
client = tasks_v2.CloudTasksClient()
Expand Down Expand Up @@ -63,21 +58,6 @@ def create_http_task(
# Add the payload to the request.
task["http_request"]["body"] = converted_payload

if in_seconds is not None:
# Convert "seconds from now" into an rfc3339 datetime string.
d = datetime.datetime.utcnow() + datetime.timedelta(seconds=in_seconds)

# Create Timestamp protobuf.
timestamp = timestamp_pb2.Timestamp()
timestamp.FromDatetime(d)

# Add the timestamp to the tasks.
task["schedule_time"] = timestamp

if task_name is not None:
# Add the name to tasks.
task["name"] = task_name

# Use the client to build and send the task.
response = client.create_task(request={"parent": parent, "task": task})

Expand Down