<@ULVA73B9P> in Prefect 2.14.3 is it possible to e...
# ask-marvin
d
@Marvin in Prefect 2.14.3 is it possible to ensure a flow doesn't kick off until a separate flow has completed?
m
In Prefect 2.14.3, you can ensure that a flow doesn't start until a separate flow has completed by specifying upstream dependencies. This can be achieved using the
wait_for
parameter in your flow or task definitions. Here's a basic example:
Copy code
python
from prefect import flow, task

@task
def task_a():
    pass

@task
def task_b():
    pass

@flow
def first_flow():
    result = task_a.submit()
    return result

@flow
def second_flow():
    # Wait for first_flow to complete
    result = first_flow()
    task_b.submit(wait_for=[result])

# Run the second flow, which will wait for the first flow to complete
second_flow()
In this example,
second_flow
will not proceed to execute
task_b
until
first_flow
has completed. For more details, you can refer to the Prefect documentation on specifying upstream dependencies.
d
@Marvin what if the flows are on separate Deployments? Is this still possible?
m
In Prefect 2.14.3, orchestrating flow dependencies across separate deployments is a bit more involved than within a single deployment. However, it is possible through the use of Prefect's orchestration capabilities, such as using triggers or external orchestration logic. Here's a general approach: 1. Use Prefect API or Cloud: You can use the Prefect API or Prefect Cloud to monitor the completion of one deployment and trigger another. This involves setting up a listener or a callback that waits for the first flow to complete and then triggers the second deployment. 2. External Orchestration: Use an external orchestration tool or script to manage the dependencies. This script can check the status of the first deployment and trigger the second one upon completion. 3. Prefect Triggers: You can use Prefect's built-in triggers to create conditional logic that might help in some scenarios, although this is more commonly used within a single flow rather than across deployments. 4. Custom Automation: Implement a custom automation script that uses Prefect's Python client to check the state of a flow run and trigger another deployment when the desired state is reached. For more details on managing deployments, you can refer to the Prefect documentation on deployments.