问题
Is there an elegant way to define callback for DAG succeed event? I really don't want to set a task which will be upstream of all other tasks with on_sucess_callback.
Thanks!
回答1:
So if I understand correctly, the last step of your DAG is, in case of success, to call back to some other system. So I would encourage you to model your DAG exactly that way.
Why would you try to hide that part from the logic of your DAG? That's exactly what the up/downstream modeling is for. Hiding part of the DAG logic for the sake of the graph's aesthetics sounds like a bad tradeoff to me.
I would discourage you to set the callback task as downstream to all tasks, it should be downstream only to final tasks in the DAG.
回答2:
Don't know how much it helps you now, but the functionality you are looking for exists in Airflow 1.10... a DAG has an on_success_callback
https://airflow.apache.org/code.html#airflow.models.DAG
回答3:
Create the task and set up the upstream programmatically, that way you can't forget to add one, so long as this is done last in the file.
for task in dag.tasks:
final_task.set_upstream(task)
# Only run if all the other tasks succeeded. EDIT: This is the default
final_task.trigger_rule = 'all_success'
dag.add_task(final_task)
来源:https://stackoverflow.com/questions/48164160/airflow-dag-success-callback