Hey team! Im trying to use the `on_failure` callba...
# ask-community
s
Hey team! Im trying to use the
on_failure
callback of a flow to send a message to a slack channel that ideally looks something like “OH MAN THE FLOW FAILED - Click here to see the flow” with a proper link. Does the flow object contain any information I can use to construct a useful URL, specifically the flow_id?
a
Why not use the
slack_notifier
state handler instead? https://docs.prefect.io/core/advanced_tutorials/slack-notifications.html You can set it to notify only on failed states, and it comes packaged with the URL you have in mind.
upvote 1
s
Ah this is a farrrr superior solution, Ive been working off this page (https://docs.prefect.io/core/concepts/notifications.html#responding-to-state) with the slack examples, had no idea they had other better slack examples hidden away! Thanks Amanda, really appreciate it!
@Amanda Wee Im hoping youve used the slack notifier before, so running this with you before I raise a bug report: The slack notifier works when you attach it as a state_handler, but does not work when you attach it via
on_failure
. I cant see this caveat documented and it certainly seems unintuitive given the on_failure was meant to be a subset of state_handler
a
I've used
slack_notifier
, but not with
on_failure
, so I'm afraid that I can't say anything about that.
Okay, a quick check of the API explains why: the signature of the callback expected for a state handler is different from the signature of the callback expected for
on_failure
, i.e., a generic state handler must accept both old state and new state, whereas on failure the callback only needs to accept the new state, i.e., the specific failure state.
upvote 1
s
Ah that does make sense. Thanks for the help 🙂