Predictive Hacks

How to interact with Airflow via the Command Line

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

Share This Post

Share on facebook
Share on linkedin
Share on twitter
Share on email

Subscribe To Our Newsletter

Get updates and learn from the best

More To Explore

Python

Image Captioning with HuggingFace

Image captioning with AI is a fascinating application of artificial intelligence (AI) that involves generating textual descriptions for images automatically.

Python

Intro to Chatbots with HuggingFace

In this tutorial, we will show you how to use the Transformers library from HuggingFace to build chatbot pipelines. Let’s