Skip to content

Commit ce812ad

Browse files
authored
Merge branch 'main' into ui/time-schedule
2 parents 8b07bed + fe58952 commit ce812ad

417 files changed

Lines changed: 36709 additions & 2837 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎airflow-core/docs/administration-and-deployment/dag-serialization.rst‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ The system automatically fills in any missing values by walking up the hierarchy
187187
MappedOperator Default Handling
188188
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
189189

190-
MappedOperators (dynamic task mapping) also participate in the default value system:
190+
MappedOperators (task mapping) also participate in the default value system:
191191

192192
.. code-block:: python
193193

‎airflow-core/docs/administration-and-deployment/task-and-asset-state-store.rst‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,9 @@ Example skeleton:
203203
class S3StateBackend(BaseStoreBackend):
204204
205205
def _task_ref(self, scope: TaskScope, key: str) -> str:
206-
return f"airflow/task-store/{scope.dag_id}/{scope.run_id}/{scope.task_id}/{scope.map_index}/{key}"
206+
# Two regions can hold the same task_id and map_index, so region_id must be part of the ref.
207+
region = f"region={scope.region_id}/" if scope.region_id.int else ""
208+
return f"airflow/task-store/{scope.dag_id}/{scope.run_id}/{region}{scope.task_id}/{scope.map_index}/{key}"
207209
208210
def _asset_ref(self, scope: AssetScope, key: str) -> str:
209211
import hashlib

‎airflow-core/docs/authoring-and-scheduling/deferring.rst‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ After the trigger has finished executing, the task may be sent back to the worke
395395
start_from_trigger: bool,
396396
**kwargs: dict[str, Any],
397397
) -> None:
398-
# This whole method will be skipped during dynamic task mapping.
398+
# This whole method will be skipped during task mapping.
399399
400400
super().__init__(*args, **kwargs)
401401
self.start_trigger_args.trigger_kwargs = trigger_kwargs

‎airflow-core/docs/authoring-and-scheduling/dynamic-task-mapping.rst‎

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,29 @@
1616
under the License.
1717
1818
.. _dynamic-task-mapping:
19+
.. _mapped-tasks:
1920

20-
====================
21-
Dynamic Task Mapping
22-
====================
21+
============
22+
Mapped tasks
23+
============
2324

24-
Dynamic Task Mapping allows a way for a workflow to create a number of tasks at runtime based upon current data, rather than the Dag author having to know in advance how many tasks would be needed.
25+
Task mapping, also called dynamic task mapping, allows a way for a workflow to create a number of tasks at runtime based upon current data, rather than the Dag author having to know in advance how many tasks would be needed.
2526

2627
This is similar to defining your tasks in a for loop, but instead of having the DAG file fetch the data and do that itself, the scheduler can do this based on the output of an upstream task.
27-
Unlike a Python for-loop executed at DAG parse time, dynamic task mapping defers task creation until runtime, allowing the scheduler to determine the exact number of task instances based on upstream task outputs.
28+
Unlike a Python for-loop executed at DAG parse time, task mapping defers task creation until runtime, allowing the scheduler to determine the exact number of task instances based on upstream task outputs.
2829
Right before a mapped task is executed the scheduler will create *n* copies of the task, one for each input.
2930

3031
It is also possible to have a task operate on the collected output of a mapped task, commonly known as map and reduce.
3132

33+
.. seealso::
34+
Not sure whether you need mapped tasks or a loop? See :ref:`loops-and-mapped-tasks`.
35+
3236
Simple mapping
3337
==============
3438

3539
In its simplest form you can map over a list defined directly in your Dag file using the ``expand()`` function instead of calling your task directly.
3640

37-
If you want to see a simple usage of Dynamic Task Mapping, you can look below:
41+
If you want to see a simple usage of task mapping, you can look below:
3842

3943
.. exampleinclude:: /../src/airflow/example_dags/example_dynamic_task_mapping.py
4044
:language: python
@@ -388,7 +392,7 @@ For example, this code will *not* work:
388392
389393
When code in ``my_task_group`` is executed, ``value`` would still only be a reference, not the real value, so the ``if not value`` branch will not work as you likely want. However, if you pass that reference into a task, it will become resolved when the task is executed, and the three ``my_task`` instances will therefore receive 1, 2, and 3, respectively.
390394

391-
It is, therefore, important to remember that, if you intend to perform any logic on a value passed into a task group function, you must always use a task to run the logic, such as ``@task.branch`` (or ``BranchPythonOperator``) for conditions, and task mapping methods for loops.
395+
It is, therefore, important to remember that, if you intend to perform any logic on a value passed into a task group function, you must always use a task to run the logic, such as ``@task.branch`` (or ``BranchPythonOperator``) for conditions, and ``expand()`` to iterate over values. To repeat a group of tasks, see :ref:`loops-and-mapped-tasks`.
392396

393397
.. note:: Task-mapping in a mapped task group is not permitted
394398

‎airflow-core/docs/authoring-and-scheduling/index.rst‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ It's recommended that you first review the pages in :doc:`core concepts </core-c
3131
deferring
3232
serializers
3333
connections
34+
loops-and-mapped-tasks
3435
dynamic-task-mapping
36+
loops
3537
assets
3638
dag-result
3739
Non-Python Task SDKs <language-sdks/index>
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
.. Licensed to the Apache Software Foundation (ASF) under one
2+
or more contributor license agreements. See the NOTICE file
3+
distributed with this work for additional information
4+
regarding copyright ownership. The ASF licenses this file
5+
to you under the Apache License, Version 2.0 (the
6+
"License"); you may not use this file except in compliance
7+
with the License. You may obtain a copy of the License at
8+
9+
.. http://www.apache.org/licenses/LICENSE-2.0
10+
11+
.. Unless required by applicable law or agreed to in writing,
12+
software distributed under the License is distributed on an
13+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
KIND, either express or implied. See the License for the
15+
specific language governing permissions and limitations
16+
under the License.
17+
18+
.. _loops-and-mapped-tasks:
19+
20+
======================
21+
Loops and mapped tasks
22+
======================
23+
24+
A Dag does not have to be static. How much work it does can depend on data that only exists at
25+
runtime: how many files arrived, what the previous step found, or whether an answer is good enough
26+
yet. Airflow has two features for this, as well as mechanisms like ``retries`` and dynamic Dag generation that fit adjacent use cases.
27+
28+
Choose a mechanism
29+
==================
30+
31+
.. list-table::
32+
:header-rows: 1
33+
:widths: 30 30 40
34+
35+
* - You want to
36+
- Use
37+
- How it works
38+
* - Run the same task once for each item in a collection
39+
- :ref:`Mapped tasks <mapped-tasks>`
40+
- ``task.expand(...)`` creates one task instance per item once the collection is known. The
41+
instances can run concurrently.
42+
* - Repeat a group of tasks, each iteration building on the result of the previous one, until a
43+
condition is met
44+
- :ref:`Loops <loops>`
45+
- ``task_group.loop(...)`` creates the next iteration of task instances only if the last iteration says
46+
another is needed.
47+
* - Give a failed task another try
48+
- Retries, set with ``retries`` on the task. See :doc:`/core-concepts/tasks`.
49+
- A retry reruns the same task instance. It does not create new task instances, and it does not advance a
50+
loop.
51+
* - Create tasks from something known when the Dag file is parsed
52+
- A Python ``for`` loop in the Dag file. See :doc:`/howto/dynamic-dag-generation`.
53+
- The Dag has the same shape in every run.
54+
55+
Use them together
56+
=================
57+
58+
An iteration of a loop can contain mapped tasks, so each iteration can fan out over a different collection of
59+
items. See :ref:`Mapped tasks inside a loop <loops-mapped-tasks>`.
60+
61+
Mapping a whole loop, nesting loops, and placing a loop inside a mapped task group are not supported.

0 commit comments

Comments
 (0)