Thursday 21 October 2021

Introduction to Airflow cli

Following are the most used airflow commands.

 

airflow initdb

Initialize metedatabase of Airflow. Airflow requires a database to be initialized before you can run tasks. If you’re just experimenting and learning Airflow, you can stick with the default SQLite option which comes by default.

 

airflow resetdb

Remove all the existing data in database, so you can start with fresh new database.

 

airflow scheduler

Start scheduler to execute dags

 

airflow webserver

Start webserver and you can access UI to interact with airflow.

 

airflow list_dags

List all the dags available in dags folder.

$ airflow list_dags
[2020-10-04 09:42:19,268] {__init__.py:50} INFO - Using executor SequentialExecutor
[2020-10-04 09:42:19,268] {dagbag.py:417} INFO - Filling up the DagBag from /Users/krishna/airflow/dags


-------------------------------------------------------------------
DAGS
-------------------------------------------------------------------
tutorial

 

airflow list_tasks {dag_name}

List all the tasks in a dag.

$ airflow list_tasks tutorial
[2020-10-04 09:43:30,877] {__init__.py:50} INFO - Using executor SequentialExecutor
[2020-10-04 09:43:30,877] {dagbag.py:417} INFO - Filling up the DagBag from /Users/krishna/airflow/dags
print_date
sleep
templated

 

airflow list_tasks {dag_name} --tree

Print dependenies of tasks in a dag.

 

$ airflow list_tasks tutorial --tree
[2020-10-04 09:44:56,149] {__init__.py:50} INFO - Using executor SequentialExecutor
[2020-10-04 09:44:56,149] {dagbag.py:417} INFO - Filling up the DagBag from /Users/krishna/airflow/dags
<Task(BashOperator): print_date>
    <Task(BashOperator): templated>
    <Task(BashOperator): sleep>

 

‘print_date’ task runs before templated and sleep tasks.

 

airflow test {dag_name} {task_name} {previous_date}

Test given task.

$airflow test tutorial print_date 2019-05-05
[2020-10-04 09:48:01,280] {__init__.py:50} INFO - Using executor SequentialExecutor
[2020-10-04 09:48:01,281] {dagbag.py:417} INFO - Filling up the DagBag from /Users/krishna/airflow/dags
[2020-10-04 09:48:01,290] {taskinstance.py:670} INFO - Dependencies all met for <TaskInstance: tutorial.print_date 2019-05-05T00:00:00+00:00 [None]>
[2020-10-04 09:48:01,295] {taskinstance.py:670} INFO - Dependencies all met for <TaskInstance: tutorial.print_date 2019-05-05T00:00:00+00:00 [None]>
[2020-10-04 09:48:01,295] {taskinstance.py:880} INFO - 
--------------------------------------------------------------------------------
[2020-10-04 09:48:01,295] {taskinstance.py:881} INFO - Starting attempt 1 of 2
[2020-10-04 09:48:01,295] {taskinstance.py:882} INFO - 
--------------------------------------------------------------------------------
[2020-10-04 09:48:01,295] {taskinstance.py:901} INFO - Executing <Task(BashOperator): print_date> on 2019-05-05T00:00:00+00:00
[2020-10-04 09:48:01,309] {bash_operator.py:113} INFO - Tmp dir root location: 
 /var/folders/tp/qybw2qy54t39ffn2l0grsdrc0000gp/T
[2020-10-04 09:48:01,310] {bash_operator.py:134} INFO - Temporary script location: /var/folders/tp/qybw2qy54t39ffn2l0grsdrc0000gp/T/airflowtmpg42m9rr7/print_datepbc72m1d
[2020-10-04 09:48:01,310] {bash_operator.py:146} INFO - Running command: date
[2020-10-04 09:48:01,315] {bash_operator.py:153} INFO - Output:
[2020-10-04 09:48:01,322] {bash_operator.py:157} INFO - Sun Oct  4 09:48:01 IST 2020
[2020-10-04 09:48:01,322] {bash_operator.py:159} INFO - Command exited with return code 0
[2020-10-04 09:48:01,327] {taskinstance.py:1057} INFO - Marking task as SUCCESS.dag_id=tutorial, task_id=print_date, execution_date=20190505T000000, start_date=20201004T041801, end_date=20201004T041801

 

 

 

Previous                                                    Next                                                    Home

No comments:

Post a Comment