I have defined a DAG in a file called tutorial_2.py
(actually a copy of the tutorial.py
provided in the airflow
tutorial, except with the dag_id
changed to tutorial_2
).
When I look inside my default, unmodified airflow.cfg
(located in ~/airflow
), I see that dags_folder
is set to /home/alex/airflow/dags
.
I do cd /home/alex/airflow; mkdir dags; cd dags; cp [...]/tutorial_2.py tutorial_2.py
. Now I have a dags
folder matching the path set in airflow.cfg
, containing the tutorial_2.py
file I created earlier.
However, when I run airflow list_dags
, I only get the names corresponding with the default, tutorial DAGs.
I would like to have tutorial_2
show up in my DAG list, so that I can begin interacting with. Neither python tutorial_2.py
nor airflow resetdb
have caused it to appear in the list.
How do I remedy this?
To create a DAG in Airflow, you always have to import the DAG class. After the DAG class, come the imports of Operators. Basically, for each Operator you want to use, you have to make the corresponding import. For example, you want to execute a Python function, you have to import the PythonOperator.
You can have as many DAGs as you want, each describing an arbitrary number of tasks. In general, each one should correspond to a single logical workflow. When searching for DAGs, Airflow only considers python files that contain the strings “airflow” and “DAG” by default.
Airflow scans the dags_folder for new DAGs every dag_dir_list_interval , which defaults to 5 minutes but can be modified. You might have to wait until this interval has passed before a new DAG appears in the UI.
I think the reason for this is because you haven't exported AIRFLOW_HOME
. Try doing: AIRFLOW_HOME="/home/alex/airflow/dags" airflow list_dags
. If that's not working than do two steps export AIRFLOW_HOME="/home/alex/airflow/dags" airflow list_dags
I believe this should work. Give it a go?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With