<@ULVA73B9P> can we pass arguments to the on_failu...
# ask-marvin
s
@Marvin can we pass arguments to the on_failure hooks? Like a message?
m
State change hooks in Prefect allow you to execute code in response to changes in flow or task run states. This enables you to define actions for specific state transitions in a workflow. While the documentation does outline having custom messages in hooks for state changes, like sending tailored notifications upon failure, there isn't direct information regarding passing custom arguments like a specific message to the
on_failure
hooks. The example given in the documentation shows how to define a notification function that is executed when a flow enters a
Failed
state:
Copy code
python
from prefect import flow
from prefect.blocks.core import Block
from prefect.settings import PREFECT_API_URL

def notify_slack(flow, flow_run, state):
    slack_webhook_block = Block.load("slack-webhook/my-slack-webhook")
    # ... code to send a notification to Slack ...
As far as the examples show, the function for the hook typically takes predefined arguments such as
flow
,
flow_run
, and
state
. Custom messages or other arguments are not explicitly mentioned in this context. For specific use cases or features not covered in the documentation, a richer understanding can sometimes be gleaned from the discussion on the project's GitHub repository or from asking the Prefect community directly. If you would like, I can search the GitHub issues for any related discussions that might provide further insight.
k
this is probably what you want