Sending custom notification when a task fail

Previously we have been using state handlers to send a customized email when any task fails in 1.0.
but in 2.0 with state handlers gone, we would have to add that logic to ALL of our flow/task definitions:

state1 = my_task1(return_state=True)
if is_failed_state(state1): send_some_custom_email()
state2 = my_task2(return_state=True)
if is_failed_state(state2): send_some_custom_email()

This approach seems cumbersome to write and maintain. Is there a way to add this custom notification logic to ALL tasks we create? (Maybe changing the notification feature in 2.0 to support custom email content?)

1 Like

Yes, it’s possible!

This post shows how you can do it by using a custom block:

and this one uses a custom decorator for task-level alerting:

lots of options, please explore various ways and report back what worked best for you :raised_hands:

Cool! These two both seem promising. I will give them a try. Thanks for the fast response here :+1:

1 Like