Hey in Prefect 1 we had: @task(_state_handlers_=[p...
# ask-community
a
Hey in Prefect 1 we had: @task(_state_handlers_=[post_to_slack]) for posting notifications (errors) to slack. How would we do this in Prefect 2?
d
There are a number of parameters named
on_...
.
on_failure
I believe is one of them. Recommend you check those out
a
there is no universal handler for any state change?
Because on prefect 1 we got the ability to post when task started running, failed and completed all in one function
No longer possible?
d
No, no universal hook
You can just add a line at the start of each task or make your own wrapper
Copy code
from prefect import task

@task(on_failure=[post_task_fail_to_slack])
@post_task_start_to_slack
def my_task():
    ...