@@ -67,16 +67,16 @@ def create_task(project, queue, location):
67
67
68
68
69
69
# [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."""
72
72
73
73
import googleapiclient .discovery
74
74
75
75
# Create a client.
76
76
client = googleapiclient .discovery .build ('cloudtasks' , 'v2beta2' )
77
77
78
78
duration_seconds = '600s'
79
- pull_options = {
79
+ lease_options = {
80
80
'maxTasks' : 1 ,
81
81
'leaseDuration' : duration_seconds ,
82
82
'responseView' : 'FULL'
@@ -85,10 +85,10 @@ def pull_task(project, queue, location):
85
85
queue_name = 'projects/{}/locations/{}/queues/{}' .format (
86
86
project , location , queue )
87
87
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 ()
90
90
91
- print ('Pulled task {}' .format (response ))
91
+ print ('Leased task {}' .format (response ))
92
92
return response ['tasks' ][0 ]
93
93
# [END cloud_tasks_pull_task]
94
94
@@ -120,43 +120,43 @@ def acknowledge_task(task):
120
120
help = create_task .__doc__ )
121
121
create_task_parser .add_argument (
122
122
'--project' ,
123
- help = 'Project of the queue to add the task to .' ,
123
+ help = 'Project ID .' ,
124
124
required = True ,
125
125
)
126
126
create_task_parser .add_argument (
127
127
'--queue' ,
128
- help = 'ID (short name) of the queue to add the task to .' ,
128
+ help = 'Queue ID (short name).' ,
129
129
required = True ,
130
130
)
131
131
create_task_parser .add_argument (
132
132
'--location' ,
133
- help = 'Location of the queue to add the task to .' ,
133
+ help = 'Location of the queue, e.g. \' us-central1 \' .' ,
134
134
required = True ,
135
135
)
136
136
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' ,
139
139
help = create_task .__doc__ )
140
- pull_and_ack_parser .add_argument (
140
+ lease_and_ack_parser .add_argument (
141
141
'--project' ,
142
- help = 'Project of the queue to pull the task from .' ,
142
+ help = 'Project ID .' ,
143
143
required = True ,
144
144
)
145
- pull_and_ack_parser .add_argument (
145
+ lease_and_ack_parser .add_argument (
146
146
'--queue' ,
147
- help = 'ID (short name) of the queue to pull the task from .' ,
147
+ help = 'Queue ID (short name).' ,
148
148
required = True ,
149
149
)
150
- pull_and_ack_parser .add_argument (
150
+ lease_and_ack_parser .add_argument (
151
151
'--location' ,
152
- help = 'Location of the queue to pull the task from .' ,
152
+ help = 'Location of the queue, e.g. \' us-central1 \' .' ,
153
153
required = True ,
154
154
)
155
155
156
156
args = parser .parse_args ()
157
157
158
158
if args .command == 'create-task' :
159
159
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 )
162
162
acknowledge_task (task )
0 commit comments