https://prefect.io logo
k

Konstantinos

10/07/2020, 6:18 PM
Hi guys, need some help with notifications upon failures: I have added a custon function that sends an email but it would very cool if the function could know the arguments that the task was run with (following instructions here. From what I have seen so far the task does not store its running args at the level of the object and the local task runner does not pass it down to the handler. The only solution i can see is storing the arguments of the run function when that is called which introduces statefulness. Am i missing sth ?
j

josh

10/07/2020, 6:34 PM
Hey @Konstantinos I don’t think task inputs are exposed to the state handlers however you could instead slightly refactor what you are doing to use the upstream task’s results in the state handler!
Copy code
def notif(tracked_obj, old_state, new_state):
    if new_state.is_successful():
        print(new_state.result)

    return new_state

@task(state_handlers=[notif])
def a():
    return 1234

@task
def b(x):
    print(x)

with Flow("test") as flow:
    a = a()
    b = b(a)
This essentially is saying instead of looking at the inputs of the downstream look at the result of the upstream (which are the inputs to the downstream)
k

Konstantinos

10/08/2020, 7:38 AM
Hello @josh, thanks for the input. I guess if we are talking about tasks without upstream, then i can define a dummy upstream essentially returning the input of downstream. 🤔
might try this, thank you!