Last active
September 16, 2021 12:52
-
-
Save Nihhaar/b84ec0e02720fdcaf60b169166887a75 to your computer and use it in GitHub Desktop.
DAG factory to load dags from other directories and show load errors on the Airflow UI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import sys | |
import traceback | |
from airflow.models import DagBag | |
from airflow.utils.session import provide_session | |
from airflow.dag_processing.processor import DagFileProcessor | |
DAG_DIRS = ['<path/to/dir1>', '<path/to/dir2>', ...] | |
@provide_session | |
def build_dags(session=None): | |
for dir in DAG_DIRS: | |
# Load DAGs from directory | |
dag_bag = DagBag(dir, include_examples=False, include_smart_sensor=False) | |
if dag_bag: | |
for dag_id, dag in dag_bag.dags.items(): | |
globals()[dag_id] = dag | |
# Show errors on the Airflow UI | |
DagFileProcessor.update_import_errors(session, dag_bag) | |
if __name__ == '__main__': | |
build_dags() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment