Defaults
DAG Factory allows you to define Airflow
default_args and
additional DAG-level arguments in a default
block. This block enables you to share common settings across all DAGs in
your YAML configuration, with the arguments automatically applied to each DAG defined in the file.
Benefits of using the default block
- Consistency: Ensures uniform configurations across all tasks and DAGs.
- Maintainability: Reduces duplication by centralizing common properties.
- Simplicity: Makes configurations easier to read and manage.
Example usage of default block
default:
default_args:
owner: default_owner
retries: 1
retry_delay_sec: 300
start_date: 2024-01-01
default_view: tree
max_active_runs: 1
schedule_interval: 0 1 * * *
example_task_group:
description: "this dag uses task groups"
task_groups:
task_group_1:
tooltip: "this is a task group"
dependencies: [task_1]
task_group_2:
tooltip: "this is a task group"
parent_group_name: task_group_1
tasks:
task_1:
operator: airflow.operators.bash_operator.BashOperator
bash_command: "echo 1"
task_2:
operator: airflow.operators.bash_operator.BashOperator
bash_command: "echo 2"
task_group_name: task_group_1
task_4:
operator: airflow.operators.bash_operator.BashOperator
bash_command: "echo 4"
task_group_name: task_group_2
The arguments specified in the default
block, such as default_args
, default_view
, max_active_runs
,
schedule_interval
, and any others defined, will be applied to all the DAGs in the YAML configuration.
Multiple ways for specifying Airflow default_args
DAG Factory offers flexibility in defining Airflow’s default_args
. These can be specified in several ways, depending on your requirements.
-
Specifying
default_args
in thedefault
blockAs seen in the previous example, you can define shared
default_args
for all DAGs in the configuration YAML under thedefault
block. These arguments are automatically inherited by every DAG defined in the file. -
Specifying
default_args
directly in a DAG configurationYou can override or define specific default_args at the individual DAG level. This allows you to customize arguments for each DAG without affecting others.
Example:
DAG level default_argsdefault: default_args: catchup: false, start_date: 2024-11-11 basic_example_dag: default_args: owner: "custom_owner" description: "this is an example dag" schedule_interval: "0 3 * * *" render_template_as_native_obj: True tasks: task_1: operator: airflow.operators.bash_operator.BashOperator bash_command: "echo 1" task_2: operator: airflow.operators.bash_operator.BashOperator bash_command: "echo 2" dependencies: [task_1] task_3: operator: airflow.operators.bash_operator.BashOperator bash_command: "echo 2" dependencies: [task_1]
-
Specifying
default_args
in a shareddefaults.yml
Starting DAG Factory 0.22.0, you can also keep the
default_args
in thedefaults.yml
file. The configuration fromdefaults.yml
will be applied to all DAG Factory generated DAGs.
Given the various ways to specify default_args
, the following precedence order is applied when arguments are
duplicated:
- In the DAG configuration
- In the
default
block within the workflow's YAML file - In the
defaults.yml