load_dag
homelab_airflow_dags.dags.load_dag ¶
Dynamic DAG loader for Apache Airflow using YAML configuration files.
This module provides functionality to dynamically load and generate Apache Airflow DAGs from YAML configuration files using the dagfactory library. It searches for YAML files in configured directories and automatically generates DAGs based on their definitions.
The module supports multiple configuration directories through environment variables and provides a default fallback to the standard Airflow DAGs folder.
Environment Variables
CONFIG_ROOT_DIRS: Colon-separated list of directories containing DAG YAML files. Example: "/path/to/dags:/another/path/to/dags" AIRFLOW_PROJ_DIR: Base directory for the Airflow project (default: /opt/airflow).
Typical usage example
This module is typically imported by Airflow to automatically load DAGs¶
The main() function is executed when the module is imported¶
YAML files should be placed in:¶
1. Directories specified in CONFIG_ROOT_DIRS environment variable¶
2. Default location: $AIRFLOW_PROJ_DIR/dags/¶
Example YAML structure:¶
my_dag:¶
default_args:¶
owner: 'airflow'¶
start_date: '2024-01-01'¶
schedule_interval: '@daily'¶
tasks:¶
task_1:¶
operator: airflow.operators.bash.BashOperator¶
bash_command: 'echo "Hello World"'¶
Note
This module automatically executes the main() function when imported, which will load all DAGs from YAML files found in the configured directories.
find_yamls ¶
Find all YAML files in the specified directories.
PARAMETER | DESCRIPTION |
---|---|
config_root_dir
|
A colon-separated string of directories to search for YAML files.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
list[str]
|
list[str]: A sorted list of paths to YAML files found in the specified directories. |
Source code in homelab_airflow_dags/dags/load_dag.py
load_dag_floders ¶
Load directories containing DAG YAML files.
RETURNS | DESCRIPTION |
---|---|
list[str]
|
list[str]: A list of directories containing YAML files. |
Source code in homelab_airflow_dags/dags/load_dag.py
load_dags ¶
Load DAGs from the specified YAML files.
PARAMETER | DESCRIPTION |
---|---|
yaml_files
|
A list of paths to YAML files containing DAG definitions.
TYPE:
|
Source code in homelab_airflow_dags/dags/load_dag.py
main ¶
Main function to load DAGs from YAML files.