From ee983d12e2e1ac0bd5aecc56e8f3501e227b0b66 Mon Sep 17 00:00:00 2001 From: Andrew Gorcester Date: Wed, 10 Jan 2018 17:26:15 -0800 Subject: [PATCH 1/3] Rename pull to lease and fix name/parent confusion --- tasks/pull_queue_snippets.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/tasks/pull_queue_snippets.py b/tasks/pull_queue_snippets.py index 360ceb2b6410..6c4775abf6d1 100644 --- a/tasks/pull_queue_snippets.py +++ b/tasks/pull_queue_snippets.py @@ -68,7 +68,7 @@ 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 @@ -76,7 +76,7 @@ def pull_task(project, queue, location): client = googleapiclient.discovery.build('cloudtasks', 'v2beta2') duration_seconds = '600s' - pull_options = { + lease_options = { 'maxTasks': 1, 'leaseDuration': duration_seconds, 'responseView': 'FULL' @@ -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] @@ -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, ) @@ -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, ) From 6eecbeb55c63eb4647fc886070435b786dab2817 Mon Sep 17 00:00:00 2001 From: Andrew Gorcester Date: Fri, 12 Jan 2018 11:55:12 -0800 Subject: [PATCH 2/3] lease instead of pull in more places --- tasks/pull_queue_snippets.py | 16 ++++++++-------- tasks/pull_queue_snippets_test.py | 4 ++-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/tasks/pull_queue_snippets.py b/tasks/pull_queue_snippets.py index 6c4775abf6d1..33711821ba7c 100644 --- a/tasks/pull_queue_snippets.py +++ b/tasks/pull_queue_snippets.py @@ -67,7 +67,7 @@ def create_task(project, queue, location): # [START cloud_tasks_pull_task] -def pull_task(project, queue, location): +def lease_task(project, queue, location): """Lease a single task from a given queue for 10 minutes.""" import googleapiclient.discovery @@ -135,20 +135,20 @@ def acknowledge_task(task): 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 from which to pull the task.', required=True, ) - pull_and_ack_parser.add_argument( + lease_and_ack_parser.add_argument( '--queue', help='ID (short name) of the queue from which to pull the task.', required=True, ) - pull_and_ack_parser.add_argument( + lease_and_ack_parser.add_argument( '--location', help='Location of the queue from which to pull the task, e.g. ' '\'us-central1\'.', @@ -159,6 +159,6 @@ def acknowledge_task(task): 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) diff --git a/tasks/pull_queue_snippets_test.py b/tasks/pull_queue_snippets_test.py index e7f9f17037a7..db514d671538 100644 --- a/tasks/pull_queue_snippets_test.py +++ b/tasks/pull_queue_snippets_test.py @@ -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) From a549eb29afc6b8296e7ebf0d393b318827aef9be Mon Sep 17 00:00:00 2001 From: Andrew Gorcester Date: Fri, 12 Jan 2018 14:44:16 -0800 Subject: [PATCH 3/3] wording --- tasks/pull_queue_snippets.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/tasks/pull_queue_snippets.py b/tasks/pull_queue_snippets.py index 33711821ba7c..12ac0e956a1c 100644 --- a/tasks/pull_queue_snippets.py +++ b/tasks/pull_queue_snippets.py @@ -120,18 +120,17 @@ def acknowledge_task(task): help=create_task.__doc__) create_task_parser.add_argument( '--project', - help='Project of the queue to which to add the task.', + help='Project ID.', required=True, ) create_task_parser.add_argument( '--queue', - help='ID (short name) of the queue to which to add the task.', + help='Queue ID (short name).', required=True, ) create_task_parser.add_argument( '--location', - help='Location of the queue to which to add the task, e.g. ' - '\'us-central1\'.', + help='Location of the queue, e.g. \'us-central1\'.', required=True, ) @@ -140,18 +139,17 @@ def acknowledge_task(task): help=create_task.__doc__) lease_and_ack_parser.add_argument( '--project', - help='Project of the queue from which to pull the task.', + help='Project ID.', required=True, ) lease_and_ack_parser.add_argument( '--queue', - help='ID (short name) of the queue from which to pull the task.', + help='Queue ID (short name).', required=True, ) lease_and_ack_parser.add_argument( '--location', - help='Location of the queue from which to pull the task, e.g. ' - '\'us-central1\'.', + help='Location of the queue, e.g. \'us-central1\'.', required=True, )