Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename pull to lease and fix name/parent confusion #1311

Merged
merged 3 commits into from Jan 12, 2018
Merged
Changes from 1 commit
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
24 changes: 13 additions & 11 deletions tasks/pull_queue_snippets.py
Expand Up @@ -68,15 +68,15 @@ def create_task(project, queue, location):

# [START cloud_tasks_pull_task]
def pull_task(project, queue, location):
"""Pull a single task from a given queue and lease it for 10 minutes."""
"""Lease a single task from a given queue for 10 minutes."""

import googleapiclient.discovery

# Create a client.
client = googleapiclient.discovery.build('cloudtasks', 'v2beta2')

duration_seconds = '600s'
pull_options = {
lease_options = {
'maxTasks': 1,
'leaseDuration': duration_seconds,
'responseView': 'FULL'
Expand All @@ -85,10 +85,10 @@ def pull_task(project, queue, location):
queue_name = 'projects/{}/locations/{}/queues/{}'.format(
project, location, queue)

response = client.projects().locations().queues().tasks().pull(
name=queue_name, body=pull_options).execute()
response = client.projects().locations().queues().tasks().lease(
parent=queue_name, body=lease_options).execute()

print('Pulled task {}'.format(response))
print('Leased task {}'.format(response))
return response['tasks'][0]
# [END cloud_tasks_pull_task]

Expand Down Expand Up @@ -120,17 +120,18 @@ def acknowledge_task(task):
help=create_task.__doc__)
create_task_parser.add_argument(
'--project',
help='Project of the queue to add the task to.',
help='Project of the queue to which to add the task.',
required=True,
)
create_task_parser.add_argument(
'--queue',
help='ID (short name) of the queue to add the task to.',
help='ID (short name) of the queue to which to add the task.',
required=True,
)
create_task_parser.add_argument(
'--location',
help='Location of the queue to add the task to.',
help='Location of the queue to which to add the task, e.g. '
'\'us-central1\'.',
required=True,
)

Expand All @@ -139,17 +140,18 @@ def acknowledge_task(task):
help=create_task.__doc__)
pull_and_ack_parser.add_argument(
'--project',
help='Project of the queue to pull the task from.',
help='Project of the queue from which to pull the task.',
required=True,
)
pull_and_ack_parser.add_argument(
'--queue',
help='ID (short name) of the queue to pull the task from.',
help='ID (short name) of the queue from which to pull the task.',
required=True,
)
pull_and_ack_parser.add_argument(
'--location',
help='Location of the queue to pull the task from.',
help='Location of the queue from which to pull the task, e.g. '
'\'us-central1\'.',
required=True,
)

Expand Down