Get Exception details on Airflow on_failure_callback context

An on_failure_callback can be supplied to the DAG and/or individual tasks. In the first case (supplying to the DAG), there is no ‘exception’ in the context (the argument Airflow calls your on_failure_callback with). In the second case (supplying to a task), there is. The contained object should be a python Exception. It’s surprisingly non-intuitive to … Read more

Use case of dummy operator in Apache Airflow

Operator that does literally nothing. It can be used to group tasks in a DAG. https://airflow.apache.org/_api/airflow/operators/dummy_operator/index.html As far as I know, at least two use case: test purpose: in DAGs, the dummy operation is just between upstream and downstream, later, you can replace the true operator. Workflow purpose: BranchPythonOperator works with DummyOperator. If you want … Read more

Make custom Airflow macros expand other macros

Here are some solutions: 1. Override BashOperator to add some values to the context class NextExecutionDateAwareBashOperator(BashOperator): def render_template(self, attr, content, context): dag = context[‘dag’] execution_date = context[‘execution_date’] context[‘next_execution_date’] = dag.following_schedule(execution_date) return super().render_templates(attr, content, context) # or in python 2: # return super(NextExecutionDateAwareBashOperator, self).render_templates(attr, content, context) The good part with this approach: you can capture some … Read more

Use case of dummy operator

Operator that does literally nothing. It can be used to group tasks in a DAG. https://airflow.apache.org/_api/airflow/operators/dummy_operator/index.html as far as I know, at least to two case: test purpose. in dags, the dummy operation just between upstream and downstream, later, you can replace the true operator. Workflow purpose: BranchPythonOperator work with DummyOperator. If you want to … Read more