-
Notifications
You must be signed in to change notification settings - Fork 0
/
triggerdagop_controller_dag.py
34 lines (29 loc) · 1.04 KB
/
triggerdagop_controller_dag.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import pprint as pp
import airflow.utils.dates
from airflow import DAG
from airflow.operators.dagrun_operator import TriggerDagRunOperator
from airflow.operators.dummy_operator import DummyOperator
default_args = {
"owner": "airflow",
"start_date": airflow.utils.dates.days_ago(1)
}
def conditionally_trigger(context, dag_run_obj):
if context['params']['condition_param']:
dag_run_obj.payload = {
'message': context['params']['message']
}
pp.pprint(dag_run_obj.payload)
return dag_run_obj
with DAG(dag_id="triggerdagop_controller_dag", default_args=default_args, schedule_interval="@once") as dag:
trigger = TriggerDagRunOperator(
task_id="trigger_dag",
trigger_dag_id="triggerdagop_target_dag",
provide_context=True,
python_callable=conditionally_trigger,
params={
'condition_param': True,
'message': 'Hi from the controller'
},
)
last_task = DummyOperator(task_id="last_task")
trigger >> last_task