Victor
03/05/2025, 3:59 PMMarvin
03/05/2025, 3:59 PMwait_for_flow_run
function. This function allows you to wait for a specific flow run to complete before proceeding with other operations.
Here's a basic outline of how you can achieve this:
1. Run the First Flow: Start by running your initial flow and obtain the flow run ID.
2. Wait for Completion: Use the wait_for_flow_run
function to wait for the first flow's completion.
3. Continue with the Next Flow: Once the first flow completes, you can proceed to run the next flow.
Here's a conceptual example:
python
from prefect import flow
from prefect.client import get_client
from prefect.flow_runs import wait_for_flow_run
@flow
def first_flow():
# Your flow logic here
return "result of first flow"
@flow
def second_flow():
# Your flow logic here
print("Second flow is running after the first flow completed.")
async def run_flows():
# Run the first flow
first_flow_run = first_flow.submit()
# Wait for the first flow to complete
await wait_for_flow_run(first_flow_run.id)
# Continue with the second flow
second_flow()
# Execute the run_flows function
if __name__ == "__main__":
import asyncio
asyncio.run(run_flows())
Links for Reference:
- wait_for_flow_run in Prefect
This example assumes you're using an asynchronous environment to handle the flow runs. If you're using an imperative programming style, you'll need to ensure your environment supports asynchronous execution.Nate
03/05/2025, 4:02 PMNate
03/05/2025, 4:02 PMMarvin
03/05/2025, 4:02 PMpython
from prefect import flow
@flow
def first_flow():
# Logic for the first flow
print("Running first flow")
return "result of first flow"
@flow
def second_flow():
# Logic for the second flow
print("Running second flow")
def main():
# Run the first flow and wait for it to complete
result = first_flow()
# Continue with the second flow
second_flow()
if __name__ == "__main__":
main()
This approach works well in an imperative programming style, where you simply want one flow to execute after another without any additional orchestration or asynchronous handling. This method leverages Python's natural sequential execution.Victor
03/05/2025, 4:03 PMNate
03/05/2025, 4:04 PM