is it possible to create a helper function/task th...
# prefect-community
is it possible to create a helper function/task that implements both create_flow_run and wait_for_flow_run? I tried:
Copy code
def flow_run_helper(flow_name, project_name):
    cfr = create_flow_run(flow_name=flow_name, project_name=project_name)
    wfr = wait_for_flow_run(cfr, stream_logs=True, raise_final_state=True)
    return wfr
but its yelling at me about "ValueError: Could not infer an active Flow context while creating edge". my app does a lot of chaining of flows, so i wanted to streamline this
we have many examples using that pattern here
StartFlowRun(..., wait=True)
does it in one go
upvote 2
Copy code
from prefect import Flow
from prefect.tasks.prefect import StartFlowRun

start_flow_run = StartFlowRun(project_name="PROJECT_NAME", wait=True)

with Flow("FLOW_NAME") as flow:
    staging = start_flow_run(flow_name="child_flow_name")
i dont think i can use StartFlowRun and still get all of my child flow logs appearing in the main flow
I currently have to do all my chaining like this to get the behavior i want out of the dashboard:
Copy code
sd_id = create_flow_run(flow_name='sync_data', project_name="proj")
sd_wait = wait_for_flow_run(sd_id, stream_logs=True, raise_final_state=True)

pd_id = create_flow_run(flow_name='process_data', project_name="proj")
pd_wait = wait_for_flow_run(pd_id, stream_logs=True, raise_final_state=True)

ed_id = create_flow_run(flow_name='export_data', project_name="proj")
ed_wait = wait_for_flow_run(ed_id, stream_logs=True, raise_final_state=True)
check this Discourse page, we have 6 examples showing how you can do that
Ah I see. You function will though if you call
. To use a task inside another task:
Copy code
def abc():
but note it’s not a task. it’s just the Python function underneath
awesome, i think that's what i was looking for. ty