Skip to content

Commit 22341b9

Browse files
authored
Add Google Cloud Tasks how-to documentation (#20145)
1 parent e926275 commit 22341b9

File tree

4 files changed

+309
-0
lines changed

4 files changed

+309
-0
lines changed

airflow/providers/google/cloud/example_dags/example_tasks.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
) as dag:
7474

7575
# Queue operations
76+
# [START create_queue]
7677
create_queue = CloudTasksQueueCreateOperator(
7778
location=LOCATION,
7879
task_queue=Queue(stackdriver_logging_config=dict(sampling_ratio=0.5)),
@@ -81,31 +82,41 @@
8182
timeout=5,
8283
task_id="create_queue",
8384
)
85+
# [END create_queue]
8486

87+
# [START delete_queue]
8588
delete_queue = CloudTasksQueueDeleteOperator(
8689
location=LOCATION,
8790
queue_name=QUEUE_ID,
8891
task_id="delete_queue",
8992
)
93+
# [END delete_queue]
9094

95+
# [START resume_queue]
9196
resume_queue = CloudTasksQueueResumeOperator(
9297
location=LOCATION,
9398
queue_name=QUEUE_ID,
9499
task_id="resume_queue",
95100
)
101+
# [END resume_queue]
96102

103+
# [START pause_queue]
97104
pause_queue = CloudTasksQueuePauseOperator(
98105
location=LOCATION,
99106
queue_name=QUEUE_ID,
100107
task_id="pause_queue",
101108
)
109+
# [END pause_queue]
102110

111+
# [START purge_queue]
103112
purge_queue = CloudTasksQueuePurgeOperator(
104113
location=LOCATION,
105114
queue_name=QUEUE_ID,
106115
task_id="purge_queue",
107116
)
117+
# [END purge_queue]
108118

119+
# [START get_queue]
109120
get_queue = CloudTasksQueueGetOperator(
110121
location=LOCATION,
111122
queue_name=QUEUE_ID,
@@ -116,18 +127,23 @@
116127
task_id="get_queue_result",
117128
bash_command=f"echo {get_queue.output}",
118129
)
130+
# [END get_queue]
119131

120132
get_queue >> get_queue_result
121133

134+
# [START update_queue]
122135
update_queue = CloudTasksQueueUpdateOperator(
123136
task_queue=Queue(stackdriver_logging_config=dict(sampling_ratio=1)),
124137
location=LOCATION,
125138
queue_name=QUEUE_ID,
126139
update_mask={"paths": ["stackdriver_logging_config.sampling_ratio"]},
127140
task_id="update_queue",
128141
)
142+
# [END update_queue]
129143

144+
# [START list_queue]
130145
list_queue = CloudTasksQueuesListOperator(location=LOCATION, task_id="list_queue")
146+
# [END list_queue]
131147

132148
chain(
133149
create_queue,
@@ -141,6 +157,7 @@
141157
)
142158

143159
# Tasks operations
160+
# [START create_task]
144161
create_task = CloudTasksTaskCreateOperator(
145162
location=LOCATION,
146163
queue_name=QUEUE_ID,
@@ -150,25 +167,34 @@
150167
timeout=5,
151168
task_id="create_task_to_run",
152169
)
170+
# [END create_task]
153171

172+
# [START tasks_get]
154173
tasks_get = CloudTasksTaskGetOperator(
155174
location=LOCATION,
156175
queue_name=QUEUE_ID,
157176
task_name=TASK_NAME,
158177
task_id="tasks_get",
159178
)
179+
# [END tasks_get]
160180

181+
# [START run_task]
161182
run_task = CloudTasksTaskRunOperator(
162183
location=LOCATION,
163184
queue_name=QUEUE_ID,
164185
task_name=TASK_NAME,
165186
task_id="run_task",
166187
)
188+
# [END run_task]
167189

190+
# [START list_tasks]
168191
list_tasks = CloudTasksTasksListOperator(location=LOCATION, queue_name=QUEUE_ID, task_id="list_tasks")
192+
# [END list_tasks]
169193

194+
# [START delete_task]
170195
delete_task = CloudTasksTaskDeleteOperator(
171196
location=LOCATION, queue_name=QUEUE_ID, task_name=TASK_NAME, task_id="delete_task"
172197
)
198+
# [END delete_task]
173199

174200
chain(purge_queue, create_task, tasks_get, list_tasks, run_task, delete_task, delete_queue)

airflow/providers/google/cloud/operators/tasks.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ class CloudTasksQueueCreateOperator(BaseOperator):
3838
"""
3939
Creates a queue in Cloud Tasks.
4040
41+
.. seealso::
42+
For more information on how to use this operator, take a look at the guide:
43+
:ref:`howto/operator:CloudTasksQueueCreateOperator`
44+
4145
:param location: The location name in which the queue will be created.
4246
:type location: str
4347
:param task_queue: The task queue to create.
@@ -140,6 +144,10 @@ class CloudTasksQueueUpdateOperator(BaseOperator):
140144
"""
141145
Updates a queue in Cloud Tasks.
142146
147+
.. seealso::
148+
For more information on how to use this operator, take a look at the guide:
149+
:ref:`howto/operator:CloudTasksQueueUpdateOperator`
150+
143151
:param task_queue: The task queue to update.
144152
This method creates the queue if it does not exist and updates the queue if
145153
it does exist. The queue's name must be specified.
@@ -240,6 +248,10 @@ class CloudTasksQueueGetOperator(BaseOperator):
240248
"""
241249
Gets a queue from Cloud Tasks.
242250
251+
.. seealso::
252+
For more information on how to use this operator, take a look at the guide:
253+
:ref:`howto/operator:CloudTasksQueueGetOperator`
254+
243255
:param location: The location name in which the queue was created.
244256
:type location: str
245257
:param queue_name: The queue's name.
@@ -322,6 +334,10 @@ class CloudTasksQueuesListOperator(BaseOperator):
322334
"""
323335
Lists queues from Cloud Tasks.
324336
337+
.. seealso::
338+
For more information on how to use this operator, take a look at the guide:
339+
:ref:`howto/operator:CloudTasksQueuesListOperator`
340+
325341
:param location: The location name in which the queues were created.
326342
:type location: str
327343
:param project_id: (Optional) The ID of the Google Cloud project that owns the Cloud Tasks.
@@ -409,6 +425,10 @@ class CloudTasksQueueDeleteOperator(BaseOperator):
409425
"""
410426
Deletes a queue from Cloud Tasks, even if it has tasks in it.
411427
428+
.. seealso::
429+
For more information on how to use this operator, take a look at the guide:
430+
:ref:`howto/operator:CloudTasksQueueDeleteOperator`
431+
412432
:param location: The location name in which the queue will be deleted.
413433
:type location: str
414434
:param queue_name: The queue's name.
@@ -488,6 +508,10 @@ class CloudTasksQueuePurgeOperator(BaseOperator):
488508
"""
489509
Purges a queue by deleting all of its tasks from Cloud Tasks.
490510
511+
.. seealso::
512+
For more information on how to use this operator, take a look at the guide:
513+
:ref:`howto/operator:CloudTasksQueuePurgeOperator`
514+
491515
:param location: The location name in which the queue will be purged.
492516
:type location: str
493517
:param queue_name: The queue's name.
@@ -570,6 +594,10 @@ class CloudTasksQueuePauseOperator(BaseOperator):
570594
"""
571595
Pauses a queue in Cloud Tasks.
572596
597+
.. seealso::
598+
For more information on how to use this operator, take a look at the guide:
599+
:ref:`howto/operator:CloudTasksQueuePauseOperator`
600+
573601
:param location: The location name in which the queue will be paused.
574602
:type location: str
575603
:param queue_name: The queue's name.
@@ -652,6 +680,10 @@ class CloudTasksQueueResumeOperator(BaseOperator):
652680
"""
653681
Resumes a queue in Cloud Tasks.
654682
683+
.. seealso::
684+
For more information on how to use this operator, take a look at the guide:
685+
:ref:`howto/operator:CloudTasksQueueResumeOperator`
686+
655687
:param location: The location name in which the queue will be resumed.
656688
:type location: str
657689
:param queue_name: The queue's name.
@@ -734,6 +766,10 @@ class CloudTasksTaskCreateOperator(BaseOperator):
734766
"""
735767
Creates a task in Cloud Tasks.
736768
769+
.. seealso::
770+
For more information on how to use this operator, take a look at the guide:
771+
:ref:`howto/operator:CloudTasksTaskCreateOperator`
772+
737773
:param location: The location name in which the task will be created.
738774
:type location: str
739775
:param queue_name: The queue's name.
@@ -836,6 +872,10 @@ class CloudTasksTaskGetOperator(BaseOperator):
836872
"""
837873
Gets a task from Cloud Tasks.
838874
875+
.. seealso::
876+
For more information on how to use this operator, take a look at the guide:
877+
:ref:`howto/operator:CloudTasksTaskGetOperator`
878+
839879
:param location: The location name in which the task was created.
840880
:type location: str
841881
:param queue_name: The queue's name.
@@ -930,6 +970,10 @@ class CloudTasksTasksListOperator(BaseOperator):
930970
"""
931971
Lists the tasks in Cloud Tasks.
932972
973+
.. seealso::
974+
For more information on how to use this operator, take a look at the guide:
975+
:ref:`howto/operator:CloudTasksTasksListOperator`
976+
933977
:param location: The location name in which the tasks were created.
934978
:type location: str
935979
:param queue_name: The queue's name.
@@ -1024,6 +1068,10 @@ class CloudTasksTaskDeleteOperator(BaseOperator):
10241068
"""
10251069
Deletes a task from Cloud Tasks.
10261070
1071+
.. seealso::
1072+
For more information on how to use this operator, take a look at the guide:
1073+
:ref:`howto/operator:CloudTasksTaskDeleteOperator`
1074+
10271075
:param location: The location name in which the task will be deleted.
10281076
:type location: str
10291077
:param queue_name: The queue's name.
@@ -1109,6 +1157,10 @@ class CloudTasksTaskRunOperator(BaseOperator):
11091157
"""
11101158
Forces to run a task in Cloud Tasks.
11111159
1160+
.. seealso::
1161+
For more information on how to use this operator, take a look at the guide:
1162+
:ref:`howto/operator:CloudTasksTaskRunOperator`
1163+
11121164
:param location: The location name in which the task was created.
11131165
:type location: str
11141166
:param queue_name: The queue's name.

airflow/providers/google/provider.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ integrations:
169169
tags: [gcp]
170170
- integration-name: Google Cloud Tasks
171171
external-doc-url: https://cloud.google.com/tasks/
172+
how-to-guide:
173+
- /docs/apache-airflow-providers-google/operators/cloud/tasks.rst
172174
logo: /integration-logos/gcp/Cloud-Tasks.png
173175
tags: [gcp]
174176
- integration-name: Google Cloud Text-to-Speech

0 commit comments

Comments
 (0)