https://prefect.io logo
Title
c

Chris Arderne

02/13/2023, 6:32 PM
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

Zanie

02/13/2023, 7:25 PM
Like including
return_state=True
on the flow call?
Or do you need it for deployed runs?
c

Chris Arderne

02/13/2023, 7:26 PM
Yes for deployed runs (running on
KubernetesJob
)
z

Zanie

02/13/2023, 7:28 PM
Adding these hooks is on our roadmap
c

Chris Arderne

02/13/2023, 7:28 PM
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

Zanie

02/13/2023, 7:28 PM
You can return a state manually
Is that what you mean you’re doing for 1.?
c

Chris Arderne

02/13/2023, 7:30 PM
I'm doing this:
@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.