We have a lot of DAGs running on Airflow. When something fails, we want to be notified, or make a specific action: I have tried via decorator
def on_failure_callback(f):
@wraps(f)
def wrap(*args, **kwargs):
try:
return f(*args, **kwargs)
except Exception as e:
return f"An exception {e} on ocurred on{f}"
return wrap
This works, but it is necessary to decorate any function we want to have this behavior on.
I saw this and try to implement it like this:
def on_failure_callback(context):
operator = PythonOperator(
python_callable=failure)
return operator.execute(context=context)
def failure():
return 'Failure in the failure func'
dag_args = {
"retries": 2,
"retry_delay": timedelta(minutes=2),
'on_failure_callback': on_failure_callback
}
And then on the DAG definition, I use [...] default_args=dag_args [...]
, but this option is not working.
What is the best way to accomplish this?
Thanks