We will provide some airflow commands when you want to work with the terminal. We will work with the Airflow version 2.0.1
How to get the Airflow version
airflow version
How to get the description of the commands
airflow -h
How to get a list of active DAGs
This command can be used from troubleshooting too, since if there is an issue with a DAG you will get the error.
airflow dags list
How to Run a Task
If you want to run a task the syntax is airflow tasks run <dag_id> <task_id> <start_date>
. So, in my case, the dag id is my_sample_dag
and the task id is the run_this_first
.
airflow tasks run my_sample_dag run_this_first now
Start the Webserver
You can stat the webserver to access the Airflow UI by running the command. Note that you can change the port. Here we chose the 8080
.
airflow webserver -p 8080
Initialize the database tables
airflow db init
How to get a list of tasks for a specific DAG
Let’s print the list of tasks in the “my_sample_dag” DAG
airflow tasks list my_sample_dag
and if we want to get it in a tree mode:
airflow tasks list my_sample_dag --tree
How to test your tasks within DAG
Let’s test the my_sample_dag
and the task run_this_first
. The date specified in this context is called execution_date
. This is the logical date, which simulates the scheduler running your task or dag at a specific date and time, even though it physically will run now ( or as soon as its dependencies are met).
airflow tasks test my_sample_dag run_this_first 2021-04-04