dstandish commented on code in PR #32053:
URL: https://github.com/apache/airflow/pull/32053#discussion_r1242429904
##########
airflow/example_dags/example_setup_teardown_taskflow.py:
##########
@@ -29,30 +29,56 @@
catchup=False,
tags=["example"],
) as dag:
- # You can use the setup and teardown decorators to add setup and teardown
tasks at the DAG level
- @setup
+
@task
- def root_setup():
- print("Hello from root_setup")
+ def task_1():
+ print("Hello 1")
- @teardown
@task
- def root_teardown():
- print("Goodbye from root_teardown")
+ def task_2():
+ print("Hello 2")
@task
- def normal():
+ def task_3():
+ print("Hello 3")
+
+ # you can set setup / teardown relationships with the `as_teardown` method.
+ t1 = task_1()
+ t2 = task_2()
+ t3 = task_3()
+ t1 >> t2 >> t3.as_teardown(t1)
+
+ # now if you clear t2 (downstream), then t1 will be cleared in addition to
t3
+
+ # it's also possible to mark a task as setup or teardown when you define it
+
+ @setup
+ def dag_setup():
+ print("I am dag_setup")
+
+ @teardown
+ def dag_teardown():
+ print("I am dag_teardown")
+
+ @task
+ def dag_normal_task():
print("I am just a normal task")
+ # since we already marked these as setup / teardown, we just need to make
sure they are linked
+ # here we make sure setup and teardown are connected.
+ # if not using `as_teardown` we must arrow them explicitly
+ s = dag_setup()
+ t = dag_teardown()
+ s >> t
+ # and here we add our "work" task a.k.a. normal task.
+ s >> dag_normal_task() >> t
Review Comment:
updated
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]