84c43177c6cc611daf5e141339065d8969b3c089,tasks/pull_queue_snippets.py,,lease_task,#Any#Any#Any#,70
Before Change
import googleapiclient.discovery
// Create a client.
client = googleapiclient.discovery.build("cloudtasks", "v2beta2")
duration_seconds = "600s"
lease_options = {
"maxTasks": 1,
"leaseDuration": duration_seconds,
"responseView": "FULL"
}
queue_name = "projects/{}/locations/{}/queues/{}".format(
project, location, queue)
response = client.projects().locations().queues().tasks().lease(
parent=queue_name, body=lease_options).execute()
print("Leased task {}".format(response))
return response["tasks"][0]
def acknowledge_task(task):
After Change
from google.cloud import tasks_v2beta2
// Create a client.
client = tasks_v2beta2.CloudTasksClient()
// Construct the fully qualified queue name.
parent = client.queue_path(project, location, queue)
lease_duration = {"seconds": 600}
// Send lease request to client.
response = client.lease_tasks(
parent, lease_duration, max_tasks=1, response_view="FULL")
task = response.tasks[0]
print("Leased task {}".format(task.name))
return task
In pattern: SUPERPATTERN
Frequency: 3
Non-data size: 12
Instances
Project Name: GoogleCloudPlatform/python-docs-samples
Commit Name: 84c43177c6cc611daf5e141339065d8969b3c089
Time: 2018-06-18
Author: akitsch@google.com
File Name: tasks/pull_queue_snippets.py
Class Name:
Method Name: lease_task
Project Name: GoogleCloudPlatform/python-docs-samples
Commit Name: 6f9eacfd1d5f6ebf961d134f538e7613c0b9fc25
Time: 2019-01-07
Author: d.sanche14@gmail.com
File Name: kms/api-client/snippets.py
Class Name:
Method Name: enable_crypto_key_version
Project Name: GoogleCloudPlatform/python-docs-samples
Commit Name: 6f9eacfd1d5f6ebf961d134f538e7613c0b9fc25
Time: 2019-01-07
Author: d.sanche14@gmail.com
File Name: kms/api-client/snippets.py
Class Name:
Method Name: disable_crypto_key_version