https://prefect.io logo
Title
s

Shrikkanth

10/18/2022, 5:27 AM
Hi all, Im trying to post a message in slack after the flow gets to success state. But it shows None as the message for some reason. I have used the same function for failure and it works fine on it. I have given the flow code below First flow function try:
def post_to_slack_on_success(task, old_state, new_state):
    if new_state.is_successful():
        flow_run = FlowRunView.from_flow_run_id(prefect.context.get("flow_run_id"))
        task_run = flow_run.get_task_run(task_run_id=prefect.context.get("task_run_id"))
        msg = task_run.get_result()
    SlackTask(message=msg).run()
    flow.state_handlers.append(slack)
Second flow function try:
def post_to_slack_on_success(task, old_state, new_state):
    if new_state.is_successful():
        print(new_state)
        print(old_state)
        print("Result  :  ", new_state.result, new_state.message)
Screenshot of the alert:
1
m

Mason Menges

10/18/2022, 5:10 PM
Hey @Shrikkanth I'm fairly certain that the new_state.result for tasks is Actually None if the relevant task is not actually returning any values, this might be why it's "working" when the task fails since the exception gets returned from the task. Can you clarify what you're wanting to return from the slack message are you wanting the id, or is there some set of data you want to return with the slack message?
s

Shrikkanth

10/19/2022, 4:49 AM
Hey @Mason Menges We are trying to print the last set of data from a script which we are running using prefect flow.