# Introducing Setup and Teardown tasks

DevFeed: [Introducing Setup and Teardown tasks](<https://devfeed.tech/articles/introducing-setup-and-teardown-tasks-32564.md>)

Original publisher: [Read original article](<https://airflow.apache.org/blog/introducing_setup_teardown/>)

Author: Apache Airflow

Published: 2023-08-18T00:00:00Z

Content type: article

Language: en

Sources: [Apache Airflow Blog](<https://devfeed.tech/sources/apache-airflow-blog.md>)

Topics: [airflow](<https://devfeed.tech/topics/airflow.md>), [Data pipelines](<https://devfeed.tech/topics/data-pipelines.md>), [GPU](<https://devfeed.tech/topics/gpu.md>)

Tags: [airflow](<https://devfeed.tech/tags/airflow.md>), [blog-post](<https://devfeed.tech/tags/blog-post.md>), [cleanup](<https://devfeed.tech/tags/cleanup.md>), [data-pipelines](<https://devfeed.tech/tags/data-pipelines.md>), [dependencies](<https://devfeed.tech/tags/dependencies.md>), [setup](<https://devfeed.tech/tags/setup.md>), [tasks](<https://devfeed.tech/tags/tasks.md>)

## AI overview

This article introduces setup and teardown tasks in Airflow 2.7 for managing infrastructure around work in data pipelines. It explains their dependency semantics, cleanup behavior, DAG run state handling, and behavior within task groups.

## Source excerpt

In data pipelines, commonly we need to create infrastructure resources, like a cluster or GPU nodes in an existing cluster, before doing the actual "work" and delete them after the work is done. Airflow 2.7 adds "setup" and "teardown" tasks to better support this type of pipeline. This blog post aims to highlight the key features so you know what's possible. For full documentation on how to use setup and teardown tasks, see the setup and teardown docs. Why setup and teardown? Before we dig into examples, let me state at high level what setup and teardown bring to the table. More expressive dependencies Before setup and teardown, upstream and downstream relationships could only mean one thing: "this comes before that". With setup and teardown, in effect we can say "this requires that". And what it means in practice is, if you clear your task, and it requires a setup, that setup will be cleared too. And if that setup has a teardown, that will run again as well. Separating the work from the infra Sometimes the part of the dag you care about is not, say, the cleanup task. For example, suppose you have a dag that loads some data and then deletes temp files. As long as the data loads, you want your dag to be marked successful. By default, this is how teardown tasks work; that is, they are ignored when determining dag run state. Simple case A simple example is one setup / teardown pair, and one normal or "work" task. Setups and teardowns are indicated by the up and down arrows, respectively. From that we can see that .create_cluster is a setup task and delete_cluster is a teardown. The link between a setup and a teardown is always dotted to highlight the special relationship. Some things to observe: If create_cluster fails, neither run_query nor delete_cluster will run. If create_cluster succeeds and run_query fails, then delete_cluster will still run. If create_cluster is skipped, run_query and delete_cluster will be skipped By default, if run_query succeeds, and delete_c