Help using TriggerDagRunOperator
See original GitHub issueI running into problems use the TriggerDagRunOperator:
def foo(context, dag_run_obj):
#What goes here?
#create a DagRun?
pass
dag = DAG(dag_id='test_short_circuit_novo', default_args=args, schedule_interval=None)
task = BashOperator(
task_id='runme',
bash_command='echo run_me',
dag=dag)
trigger = TriggerDagRunOperator(task_id='trigger_other_dag', dag_id="test_trigger", python_callable=foo, dag=dag)
task.set_downstream(trigger)
trigger = TriggerDagRunOperator(task_id='trigger_other_dag', dag_id="test_trigger", python_callable=foo)
File "/home/pedro/workspace/mdm-source/env/local/lib/python2.7/site-packages/airflow/utils.py", line 472, in wrapper
result = func(*args, **kwargs)
TypeError: __init__() takes at least 3 arguments (2 given)
Does anyone can write a sample code for the def foo(context, dag_run_obj):
function?
Issue Analytics
- State:
- Created 8 years ago
- Comments:10 (6 by maintainers)
Top Results From Across the Web
The TriggerDagRunOperator in Airflow! Create DAG ...
DAG dependency in Airflow is a though topic. Or was a though topic. Indeed, with the new version of the TriggerDagRunOperator, in Airflow ......
Read more >Help using TriggerDagRunOperator · Issue #1029 - GitHub
Does anyone have an example how to use the payload with TriggerDagRunOperator? How can I get the payload on triggered dag? Can someone...
Read more >How do I trigger Airflow -dag using TriggerDagRunOperator
My understanding is that TriggerDagRunOperator is for when you want to use a python function to determine whether or not to trigger the ......
Read more >Implement DAG Dependencies Using TriggerDagRun Operator
TriggerDagRunOperator is an effective way to implement cross-DAG dependencies. The operator allows to trigger other DAGs in the same Airflow environment.
Read more >airflow.operators.trigger_dagrun
Operator link for TriggerDagRunOperator. It allows users to access DAG triggered by task using TriggerDagRunOperator. ... Link to external system. Note: The old ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @pedrorjbr, Great question and it’s very confusing, I agree. This is screaming for better documentation.
I put together an example to help you. There are some gotcha’s however that tripped me up:
schedule_interval=None
Illustrative Example: Step 1 : Define your Target DAG with
schedule_interval=None
. DAG_RUNs of this target will be created and executed every time that your trigger fires.Step 2 : Define your Controller DAG with any interval that makes sense for you! It’s going to be checking a condition on that interval and triggering the Target DAG whenever the condition is met. In the example below, I am running it every minute and always executing the trigger. The idea of the
foo
function is to check a condition and then return dag_run_obj if you want to trigger the Target DAG. If your condition is not met, then return None.Optional Step 3 : You can also manually trigger your Target DAG using the CLI, perhaps when testing or if you are using some custom automation via
trigger_dag simple_dummy_dag_v1
Your DAG_Run table will look like :
You can see 3 types of entries (from top to bottom):
run_id : manual__2016-02-15T22:57:49.996114
)run_id : trig__2016-02-15T22:26:37.425566
)run_id : scheduled__2016-02-15T11:15:00
)The documentation sucks. Please do your part and update it as and when questions are answered. I can do this one. Closing for now, but ping me here or on gitter if you need it reopened.
Let’s keep the conversation in a single issue. Let’s keep the conversation in #1029 I’ll change that title to be the same as this one ‘Help using TriggerDagRunOperator’