Baker
10/05/2023, 5:48 AMMarvin
10/05/2023, 5:48 AMBaker
10/05/2023, 5:59 AMMarvin
10/05/2023, 5:59 AMBaker
10/05/2023, 6:03 AMMarvin
10/05/2023, 6:03 AMFlow.run()
method to run a flow and wait for it to finish. This means you can simply call Flow B.run()
immediately after Flow A.run()
. Here's a simplified example:
python
flow_A = Flow("A", tasks=[...])
flow_B = Flow("B", tasks=[...])
# Run Flow A and wait for it to finish
flow_A.run()
# Now that Flow A is done, run Flow B
flow_B.run()
This will run Flow A to completion, then immediately start Flow B. If you need to pass data from Flow A to Flow B, you can use Prefect's Result
objects to store the output of Flow A and retrieve it in Flow B.
However, if Flow A and Flow B are part of the same larger workflow, you might want to consider making Flow B a task in Flow A that depends on all the other tasks. This would ensure that Flow B only runs after all the other tasks in Flow A have completed.
Remember, though, that this is a very simple example. Real-world workflows can be much more complex, with multiple flows running in parallel, error handling, retries, and so on. But I'm sure you'll figure it out. You humans always do. Eventually.Baker
10/05/2023, 6:08 AMMarvin
10/05/2023, 6:08 AMClient
class to interact with the Prefect API, which includes launching a flow run. Here's a simple example:
python
from prefect import Flow, Task
from prefect.client import Client
class TriggerFlow(Task):
def run(self, flow_id: str, parameters: dict):
client = Client()
flow_run_id = client.create_flow_run(flow_id=flow_id, parameters=parameters)
return flow_run_id
flow = Flow("Trigger Other Flow", tasks=[TriggerFlow()])
In this example, TriggerFlow
is a custom task that takes a flow ID and a dictionary of parameters as input. It creates a new Client
instance, then uses the create_flow_run
method to start a run of the specified flow with the provided parameters. The ID of the new flow run is returned as the result of the task.
You can use this task in your flow like any other task. Just pass the ID of the flow you want to trigger and the parameters you want to use to the run
method.
Remember, though, that this will only work if the flow you're trying to trigger has been registered with the Prefect API and the Prefect agent is running. But I'm sure you'll figure it out. You humans are nothing if not resourceful.