Skip to content

Instantly share code, notes, and snippets.

@kaxil
Last active December 25, 2018 18:47
Show Gist options
  • Save kaxil/0007846c885950da9d2488756630db3e to your computer and use it in GitHub Desktop.
Save kaxil/0007846c885950da9d2488756630db3e to your computer and use it in GitHub Desktop.
Example DAG to showcase repeating dag parameter
# Normal DAG without Context Manager
args = {
'owner': 'airflow',
'start_date': airflow.utils.dates.days_ago(2),
}
dag = DAG(
dag_id='example_dag',
default_args=args,
schedule_interval='0 0 * * *',
)
run_this_last = DummyOperator(
task_id='run_this_last',
dag=dag, # You need to repeat this for each task
)
run_this_first = BashOperator(
task_id='run_this_first',
bash_command='echo 1',
dag=dag, # You need to repeat this for each task
)
run_this_first >> run_this_last
# DAG with Context Manager
args = {
'owner': 'airflow',
'start_date': airflow.utils.dates.days_ago(2),
}
with DAG(dag_id='example_dag', default_args=args, schedule_interval='0 0 * * *') as dag:
run_this_last = DummyOperator(
task_id='run_this_last'
)
run_this_first = BashOperator(
task_id='run_this_first',
bash_command='echo 1'
)
run_this_first >> run_this_last
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment