|
22 | 22 |
|
23 | 23 | from airflow.models.dag import DAG |
24 | 24 | from airflow.operators.bash import BashOperator |
| 25 | +from airflow.settings import _ENABLE_AIP_52 |
25 | 26 | from airflow.utils.task_group import TaskGroup |
26 | 27 |
|
27 | | -with DAG( |
28 | | - dag_id="example_setup_teardown", |
29 | | - start_date=pendulum.datetime(2021, 1, 1, tz="UTC"), |
30 | | - catchup=False, |
31 | | - tags=["example"], |
32 | | -) as dag: |
33 | | - BashOperator.as_setup(task_id="root_setup", bash_command="echo 'Hello from root_setup'") |
34 | | - normal = BashOperator(task_id="normal", bash_command="echo 'I am just a normal task'") |
35 | | - BashOperator.as_teardown(task_id="root_teardown", bash_command="echo 'Goodbye from root_teardown'") |
| 28 | +if _ENABLE_AIP_52: |
| 29 | + with DAG( |
| 30 | + dag_id="example_setup_teardown", |
| 31 | + start_date=pendulum.datetime(2021, 1, 1, tz="UTC"), |
| 32 | + catchup=False, |
| 33 | + tags=["example"], |
| 34 | + ) as dag: |
| 35 | + BashOperator.as_setup(task_id="root_setup", bash_command="echo 'Hello from root_setup'") |
| 36 | + normal = BashOperator(task_id="normal", bash_command="echo 'I am just a normal task'") |
| 37 | + BashOperator.as_teardown(task_id="root_teardown", bash_command="echo 'Goodbye from root_teardown'") |
36 | 38 |
|
37 | | - with TaskGroup("section_1") as section_1: |
38 | | - BashOperator.as_setup(task_id="taskgroup_setup", bash_command="echo 'Hello from taskgroup_setup'") |
39 | | - BashOperator(task_id="normal", bash_command="echo 'I am just a normal task'") |
40 | | - BashOperator.as_setup( |
41 | | - task_id="taskgroup_teardown", bash_command="echo 'Hello from taskgroup_teardown'" |
42 | | - ) |
| 39 | + with TaskGroup("section_1") as section_1: |
| 40 | + BashOperator.as_setup(task_id="taskgroup_setup", bash_command="echo 'Hello from taskgroup_setup'") |
| 41 | + BashOperator(task_id="normal", bash_command="echo 'I am just a normal task'") |
| 42 | + BashOperator.as_setup( |
| 43 | + task_id="taskgroup_teardown", bash_command="echo 'Hello from taskgroup_teardown'" |
| 44 | + ) |
43 | 45 |
|
44 | | - normal >> section_1 |
| 46 | + normal >> section_1 |
0 commit comments