In this blog, we will learn about the airflow DummyOperator.So let’s get started:
What is DummyOperator in Airflow?
The DummyOperator in airflow is a simple operator that does nothing and is typically used as a placeholder in a DAG. It can be useful when you need to add an operator to a DAG for organizational purposes
How to import the airflow DummyOperator
The DummyOperator is defined in the airflow.operators.dummy_operator module and can be imported by typing the below command
from airflow.operators.dummy_operator import DummyOperator
Airflow DummyOperator arguments
DummyOperator in airflow is very simple to use. Below are the few arguments supported by DummyOperator:
- task_id(Mandatory): a unique identifier for the task.
- dag(Mandatory): the DAG object to which the task belongs.
- owner(optional): the owner of the task.
- email_on_retry (optional): if True, an email will be sent to the task’s owner whenever the task is retried after a failure.
- start_date (optional): the date and time at which the task should start running.
- retries (optional): the number of times the task should be retried in case of failure.
- retry_delay (optional): the amount of time to wait between retries.
Airflow DummyOperator example
Below is a simple example of airflow DummyOperator
from airflow import DAG from airflow.operators.dummy_operator import DummyOperator from datetime import datetime my_dag = DAG( dag_id='dummyoperator_dag', start_date=datetime(2022, 2, 21), schedule_interval='@daily' ) dummy_task = DummyOperator( task_id='dummy_task', dag=my_dag )
The DAG is named “dummyoperator_dag” and has a start date of February 21, 2022. The schedule interval for the DAG is set to run daily using the @daily
cron expression.
The DummyOperator
is named “dummy_task” and is added to the DAG. This operator does not perform any actual work and is used to represent a task that needs to be completed before other tasks in the DAG can run.
More to Explore?
How to send email from airflow
How to integrate airflow with slack