<@ULVA73B9P> is there a pre-built block or library...
# ask-marvin
m
@Marvin is there a pre-built block or library that allows us to trigger another flow from within a flow? I understand that I'm able to make subflows in the same code file, but that's not what I'm looking for here. I have an existing workflow, and I'd like to trigger another deployment (that's stored in a separate code repository) once all tasks in the main flow are done. I'm using Prefect self-hosted, so I can't use Automations.
m
In Prefect, you can create a subflow by calling a flow function within the execution of another flow. The primary flow is the "parent" flow, and the flow created within the parent is the "child" flow or "subflow". A subflow behaves like a normal flow run, with a full representation of the flow run in the backend as if it had been called separately. Here's an example of how you might define a flow and a subflow:
Copy code
from prefect import Flow, task

@task
def do_something():
    # Your task code here
    pass

@Flow("Subflow")
def subflow():
    do_something()

@Flow("Main Flow")
def main_flow():
    # Your main flow tasks here
    # ...
    # Then call the subflow
    subflow()
In this example,
subflow
is a flow that's defined separately from
main_flow
, but it's called from within
main_flow
as if it were a task. When
main_flow
runs, it will also run
subflow
. This should work for your use case, where you want to trigger another deployment (stored in a separate code repository) once all tasks in the main flow are done. You would just need to define that deployment as a flow (like
subflow
in the example), and then call it from within your main flow. Please note that this is a simplified example, and you might need to adjust it to fit your specific needs. For example, you might need to pass results from tasks in your main flow to your subflow, or handle errors that might occur in the subflow. You can find more information on how to do this in the Prefect documentation.
n
i think you're looking for
run_deployment
here
note the cli commands for deploying these are out of date, instead use
prefect deploy
m
Awesome! Looks like exactly what I need. Thanks!