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

Commit e47269c

Browse files
authored
Rename pull to lease and fix name/parent confusion [(#1311)](GoogleCloudPlatform/python-docs-samples#1311)
1 parent 2dcc80e commit e47269c

File tree

2 files changed

+21
-21
lines changed

2 files changed

+21
-21
lines changed

samples/snippets/pull_queue_snippets.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,16 @@ def create_task(project, queue, location):
6767

6868

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

7373
import googleapiclient.discovery
7474

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

7878
duration_seconds = '600s'
79-
pull_options = {
79+
lease_options = {
8080
'maxTasks': 1,
8181
'leaseDuration': duration_seconds,
8282
'responseView': 'FULL'
@@ -85,10 +85,10 @@ def pull_task(project, queue, location):
8585
queue_name = 'projects/{}/locations/{}/queues/{}'.format(
8686
project, location, queue)
8787

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

91-
print('Pulled task {}'.format(response))
91+
print('Leased task {}'.format(response))
9292
return response['tasks'][0]
9393
# [END cloud_tasks_pull_task]
9494

@@ -120,43 +120,43 @@ def acknowledge_task(task):
120120
help=create_task.__doc__)
121121
create_task_parser.add_argument(
122122
'--project',
123-
help='Project of the queue to add the task to.',
123+
help='Project ID.',
124124
required=True,
125125
)
126126
create_task_parser.add_argument(
127127
'--queue',
128-
help='ID (short name) of the queue to add the task to.',
128+
help='Queue ID (short name).',
129129
required=True,
130130
)
131131
create_task_parser.add_argument(
132132
'--location',
133-
help='Location of the queue to add the task to.',
133+
help='Location of the queue, e.g. \'us-central1\'.',
134134
required=True,
135135
)
136136

137-
pull_and_ack_parser = subparsers.add_parser(
138-
'pull-and-ack-task',
137+
lease_and_ack_parser = subparsers.add_parser(
138+
'lease-and-ack-task',
139139
help=create_task.__doc__)
140-
pull_and_ack_parser.add_argument(
140+
lease_and_ack_parser.add_argument(
141141
'--project',
142-
help='Project of the queue to pull the task from.',
142+
help='Project ID.',
143143
required=True,
144144
)
145-
pull_and_ack_parser.add_argument(
145+
lease_and_ack_parser.add_argument(
146146
'--queue',
147-
help='ID (short name) of the queue to pull the task from.',
147+
help='Queue ID (short name).',
148148
required=True,
149149
)
150-
pull_and_ack_parser.add_argument(
150+
lease_and_ack_parser.add_argument(
151151
'--location',
152-
help='Location of the queue to pull the task from.',
152+
help='Location of the queue, e.g. \'us-central1\'.',
153153
required=True,
154154
)
155155

156156
args = parser.parse_args()
157157

158158
if args.command == 'create-task':
159159
create_task(args.project, args.queue, args.location)
160-
if args.command == 'pull-and-ack-task':
161-
task = pull_task(args.project, args.queue, args.location)
160+
if args.command == 'lease-and-ack-task':
161+
task = lease_task(args.project, args.queue, args.location)
162162
acknowledge_task(task)

samples/snippets/pull_queue_snippets_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ def test_create_task():
2727
assert TEST_QUEUE_NAME in result['name']
2828

2929

30-
def test_pull_and_ack_task():
30+
def test_lease_and_ack_task():
3131
pull_queue_snippets.create_task(
3232
TEST_PROJECT_ID, TEST_QUEUE_NAME, TEST_LOCATION)
33-
task = pull_queue_snippets.pull_task(
33+
task = pull_queue_snippets.lease_task(
3434
TEST_PROJECT_ID, TEST_QUEUE_NAME, TEST_LOCATION)
3535
pull_queue_snippets.acknowledge_task(task)

0 commit comments

Comments
 (0)