https://prefect.io logo
Title
e

Edvard Kristiansen

05/06/2022, 2:21 PM
Hey, I am trying to send a notification with the state of a task when it finishes/fails. Something like "X completed with status: success". I didn't really find anything similar here other than the get_task_run_result but that seemed overkill? Also not sure how that would work to get the status? Is there any way I can call the state of the task like below?
run = DbtShellTask()

    send_notification = send_message(title = "Run Completed" , body = "The run has completed with status: "  + run.status)
At the same time, it would also be great to return any error messages on a failed run. Any idea how to do that?
k

Kevin Kho

05/06/2022, 2:22 PM
Where would you send this to? Something like Slack?
e

Edvard Kristiansen

05/06/2022, 2:24 PM
I need to send it to Teams, and I already have a script set up in Power Automate which takes a Post request with a JSON payload. So I just need to specify the message like above in the "send_message()" function I have made.
k

Kevin Kho

05/06/2022, 2:25 PM
Gotcha. You can look at number 4 in the writeup here and replace the Slack part with your function. This is attached to the task as a
state_handler
.
And you can check more on state handlers here. To surface the error inside the state handler, I think you can access it with
new_state.result
e

Edvard Kristiansen

05/06/2022, 2:27 PM
Ah, amazing! Thank you for a super speedy response! Ill try this out.