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

Commit

Permalink
Rename pull to lease and fix name/parent confusion [(#1311)](GoogleCl…
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewsg committed Jan 12, 2018
1 parent 2dcc80e commit e47269c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
38 changes: 19 additions & 19 deletions samples/snippets/pull_queue_snippets.py
Expand Up @@ -67,16 +67,16 @@ 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."""
def lease_task(project, queue, location):
"""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,43 +120,43 @@ 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 ID.',
required=True,
)
create_task_parser.add_argument(
'--queue',
help='ID (short name) of the queue to add the task to.',
help='Queue ID (short name).',
required=True,
)
create_task_parser.add_argument(
'--location',
help='Location of the queue to add the task to.',
help='Location of the queue, e.g. \'us-central1\'.',
required=True,
)

pull_and_ack_parser = subparsers.add_parser(
'pull-and-ack-task',
lease_and_ack_parser = subparsers.add_parser(
'lease-and-ack-task',
help=create_task.__doc__)
pull_and_ack_parser.add_argument(
lease_and_ack_parser.add_argument(
'--project',
help='Project of the queue to pull the task from.',
help='Project ID.',
required=True,
)
pull_and_ack_parser.add_argument(
lease_and_ack_parser.add_argument(
'--queue',
help='ID (short name) of the queue to pull the task from.',
help='Queue ID (short name).',
required=True,
)
pull_and_ack_parser.add_argument(
lease_and_ack_parser.add_argument(
'--location',
help='Location of the queue to pull the task from.',
help='Location of the queue, e.g. \'us-central1\'.',
required=True,
)

args = parser.parse_args()

if args.command == 'create-task':
create_task(args.project, args.queue, args.location)
if args.command == 'pull-and-ack-task':
task = pull_task(args.project, args.queue, args.location)
if args.command == 'lease-and-ack-task':
task = lease_task(args.project, args.queue, args.location)
acknowledge_task(task)
4 changes: 2 additions & 2 deletions samples/snippets/pull_queue_snippets_test.py
Expand Up @@ -27,9 +27,9 @@ def test_create_task():
assert TEST_QUEUE_NAME in result['name']


def test_pull_and_ack_task():
def test_lease_and_ack_task():
pull_queue_snippets.create_task(
TEST_PROJECT_ID, TEST_QUEUE_NAME, TEST_LOCATION)
task = pull_queue_snippets.pull_task(
task = pull_queue_snippets.lease_task(
TEST_PROJECT_ID, TEST_QUEUE_NAME, TEST_LOCATION)
pull_queue_snippets.acknowledge_task(task)

0 comments on commit e47269c

Please sign in to comment.