Terminal state handler Is there any way (or a plan...
# ask-community
c
Terminal state handler Is there any way (or a plan to enable) handling the terminal state of a flow run? i.e. run some custom code on flow run termination and do something with the terminal state. (Prefect v2)
Or if not, a reliable way to get the state of the Flow after all tasks have executed, whether successful or not.
Right now I'm considering calling the flow as a subflow, just so I can get its terminal state out programmatically...
z
Like including
return_state=True
on the flow call?
Or do you need it for deployed runs?
c
Yes for deployed runs (running on
KubernetesJob
)
z
Adding these hooks is on our roadmap
c
Right now what I'm trying: 1. Have some task
dummy.submit(wait_for=list_of_tasks_I_care_about).wait()
and use the result of that to determine the final state (with some extra logic as Task State != Flow State. 2. As I said above, just call the whole flow from another flow and get it's state.
z
You can return a state manually
Is that what you mean you’re doing for 1.?
c
I'm doing this:
Copy code
@task
def important_task():
    return True

@task
def dummy():
    return

@task
def insert_state_to_db(state):
    ...

@flow
def myflow():
    a = important_task.submit()
    terminal_state = dummy.submit(wait_for=[a]).wait().state.name
    insert_state_to_db(terminal_state)
I need the dummy in between, because I want
insert_state_to_db
to run regardless.
I know I can return a state from the flow, but I can't access that information without using the Orion API.