https://prefect.io logo
Title
s

Santiago Gonzalez

02/08/2022, 9:45 PM
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

Kevin Kho

02/08/2022, 9:45 PM
Did the state handler not fire? Can I see it?
s

Santiago Gonzalez

02/08/2022, 9:47 PM
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

Kevin Kho

02/08/2022, 9:48 PM
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.
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

Santiago Gonzalez

02/08/2022, 9:54 PM
Thanks, I will try.
Thanks, It worked.