<@ULVA73B9P> I'm looking to trigger a flow after c...
# ask-marvin
s
@Marvin I'm looking to trigger a flow after completion of another flow via automation and custom events.
m
To trigger a flow after the completion of another flow, you can use Prefect's state change hooks. These hooks can trigger a deployment when a flow run completes. In this case, the downstream deployment accepts the upstream flow run's result as a parameter, so you need to enable result persistence on the upstream flow. You can find an example of this in the run_deployment_on_completion.py script. Additionally, Prefect Cloud provides Automations that allow you to configure actions that Prefect executes automatically based on trigger conditions related to your flows and work pools. Using triggers and actions, you can automatically kick off flow runs, pause deployments, or send custom notifications in response to real-time monitoring events. More details can be found in the Automations documentation. Prefect Cloud also provides an interactive dashboard to analyze and take action on events that occurred in your workspace on the event feed page. More details can be found in the Events documentation.
s
@Marvin I'm looking to trigger a flow after completion of another flow via automation and custom events on version 2.13.1.
m
Based on the information I found, you can use a state change hook to trigger a deployment (or another flow) when a flow run completes. This is done by using the
state change hook
feature in Prefect. The downstream deployment (or flow) can accept the upstream flow run's result as a parameter, but you need to have result persistence enabled on the upstream flow. Here is an example:
Copy code
from prefect import flow
from prefect.deployments import run_deplo
For more details, you can check the source code here. Regarding automations and custom events, the Prefect Automations API allows for programmatic customization of trigger and action policies based on arbitrary events. Triggers can be configured not only in reaction to events, but also proactively: to trigger in the absence of an event you expect to see. More information can be found here. As for version 2.13.1, I couldn't find specific information related to your query. You may want to check the release notes for any relevant changes or enhancements.
s
@Marvin While importing run_deloyment from prefect.deployments getting a pylance error that "run_deployment" is not exported from module prefect.deployments. HOw to fix this?
m
I apologize for the confusion, but it seems there's a misunderstanding. The
run_deployment
function is not a part of the Prefect library. It might have been used in the context of a specific project or a codebase as a custom function. In Prefect, you can trigger another flow from within a flow by simply calling it like a function. Here's an example:
Copy code
from prefect import Flow

def flow1():
    # Flow definition here
    pass

def flow2():
    # Flow definition here
    pass

with Flow("Combined-Flow") as flow:
    flow1_result = flow1()
    flow2_result = flow2(upstream_tasks=[flow1_result])
In this example,
flow2
will only run after
flow1
has completed. If you want to run another flow upon completion of a flow, you can use this approach. If you're looking for a way to deploy your flow, you might want to look into Prefect Cloud or Prefect Server, which provide ways to register and run your flows. If you're still having trouble, could you provide more context or details about your specific use case or the environment you're working in?