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

Commit

Permalink
fix: Update sample comments (#58)
Browse files Browse the repository at this point in the history
* fix: Update sample comments

* fix: remove unused imports
  • Loading branch information
averikitsch committed Dec 22, 2020
1 parent cb1c361 commit 3eb30b3
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 20 deletions.
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

0 comments on commit 3eb30b3

Please sign in to comment.