Can I trigger flow when one flow ends?
# ask-community
v
Can I trigger flow when one flow ends?
k
Hey @Varun Joshi, you would need to make an outer flow and use the
StartFlowRun
task with upstream dependencies set to do this.
v
Can you lead me to some kind of documentation or an example?
j
k
Here is a small example:
Copy code
from prefect import Flow, task
from prefect.tasks.prefect.flow_run import StartFlowRun
import prefect
@task
def test(x):
    return x+1
with Flow("flowA") as flow1:
    test(1)
with Flow("flowB") as flow2:
    test(1)

flow1.register("omlds")
flow2.register("omlds")

with Flow("main") as flow:
    a = StartFlowRun("flowA", "omlds", 
                     new_flow_context=prefect.context.get('config'),
                     wait=True,
                     parameters={'x': 1})()
    b = StartFlowRun("flowA", "omlds", 
                     new_flow_context=prefect.context.get('config'),
                     wait=True,
                     parameters={'x': 2})()

    b.set_upstream(a)
flow.register("omlds")
🙌 1
c
You can also achieve this via a Cloud automation 😉
v
@Chris White I like your option the best 😁
success kid 1