Last active
April 27, 2020 20:06
-
-
Save dkinzer/ff7838c66e9e50c59d74f3e9eadc794e to your computer and use it in GitHub Desktop.
Versioned Templated Dag Example
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
from datetime import datetime, timedelta | |
import os | |
from airflow.operators.bash_operator import BashOperator | |
DEFAULT_ARGS = { "retries": 0, catchup: False, max_active_runs: 1, schedule_interval: None } | |
def create_dag(env, version): | |
dag_id = "hello_" + env | |
dag = DAG(dag_id=dag_id, default_args=DEFAULT_ARGS) | |
with dag: | |
if version > "0.1.0": | |
BashOperator( | |
task_id="xsl_transform", | |
bash_command='echo hello dave', | |
dag=dag) | |
else: | |
BashOperator( | |
task_id="xsl_transform", | |
bash_command='echo hello world', | |
dag=dag) | |
return dag |
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
from template import create_dag | |
from airflow.models import Variable | |
from airflow import DAG # Required or airflow-webserver skips file. | |
""" | |
Using the template | |
This doesn't need to be a separate file. | |
""" | |
version = Variable.get("hello_qa_version") | |
dag = create_dag("qa", version) | |
globals()[dag.dag_id] = dag | |
version = Variable.get("hello_prod_version") | |
dag = create_dag("prod", version) | |
globals()[dag.dag_id] = dag |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment