Here is my dag and task, when the task is failed it will call the on_dag_failure
.
dag = DAG('my_dag_id',
catchup=False,
schedule_interval='00 01 17 * *',
description = 'My dag desc',
default_args=default_args,
tags=['TAG_1','TAG_2'],
)
run_this_0 = BashOperator(
task_id='my_task_id',
bash_command='some cmd',
on_failure_callback = on_dag_failure,
execution_timeout=None,
dag=dag
)
In the on_dag_failure, I want to do get the tags that is define in the dag. Is there any way to get it?
def on_dag_failure(context):
tags = dag.tags #how to get the tags from the dag
tags_str = ""
for tag in tags:
tags_str += tag + " "
print(tags_str)
The
models.DAG
object should be available in thecontext
variable provided to the function: