Include / get log output of parent in child airflow task?

Viewed 146

I have an EmailOperator that is set to trigger if any of its parents fail.

some_task= BashOperator(
        task_id='some_task',
        bash_command='bash /some/path/to/script.sh'),
        execution_timeout=timedelta(minutes=30),
        dag=dag)

email_on_dest_fail = EmailOperator(
        task_id='email_alert',
        to=['me@dev.org'],
        subject='airflow error',
        html_content='Error detected from parent, see run_id={{run_id}} in airflow for more information',
        cc=[],
        trigger_rule=TriggerRule.ONE_FAILED,
        dag=dag

Is there a way to include the (possibly truncated) log output of the first failing parent task in the body of the sent email?

1 Answers

A better design pattern for this would be to use the on_failure_callback for the operator. Or set a default one for the whole DAG. This will allow any failing operator to go through a failure callback and execute your desired behaviour.

Related