Hey, I have a flow with manual task. I added a sta...
# prefect-server
s
Hey, I have a flow with manual task. I added a state handler, in order to post a Slack Message in a channel, to let know that a task is waiting for approval. Is there a way to print some kind of link to the task is running?
k
Did the state handler not fire? Can I see it?
s
Yeah, the state handler is being triggered. But I wanted to print in slack a link to the current execution, if there is a way.
k
Ah I know what you are saying. You are using the
slack_notification
right?
You can make a state handler like this and used the paused state and fire a message using the SlackTask instead. It’s configurable.
Copy code
from prefect.engine.state import Paused
def post_to_slack_on_failure(task, old_state, new_state):
    if isinstance(new_state, Paused):
        SlackTask(message=msg).run()
    return new_state
And then you can pull the task run id and stuff from the context
prefect.context.get("task_run_id")
to construct as URL to include in the message
s
Thanks, I will try.
Thanks, It worked.