Mark Reyes
09/26/2024, 10:16 PMMarvin
09/26/2024, 10:17 PMrun_deployment
function. Below is an example that demonstrates how to accomplish this:
1. Define a main flow that triggers three deployments.
2. Use asyncio.gather
to wait for all deployments to complete.
Here is a sample code snippet to demonstrate this:
python
from prefect import flow
from prefect.deployments import run_deployment
import asyncio
@flow
async def main_flow():
deployments = [
{"name": "deployment_1", "parameters": {}},
{"name": "deployment_2", "parameters": {}},
{"name": "deployment_3", "parameters": {}},
]
futures = [run_deployment(deployment["name"], parameters=deployment["parameters"]) for deployment in deployments]
# Wait for all deployments to complete
results = await asyncio.gather(*futures)
for result in results:
print(f"Deployment result: {result}")
if __name__ == "__main__":
main_flow()
### Explanation
1. Defining the Main Flow:
- An async
flow named main_flow
is defined.
- A list of deployments is created with their names and parameters.
2. Running Deployments:
- run_deployment
is called for each deployment in the list, generating a list of futures.
3. Waiting for Results:
- asyncio.gather
is used to wait for all the futures to complete and collect their results.
- The results are then printed.
### Sources
- Prefect Deployment Documentation
You may need to adjust the deployment names and parameters according to your specific use case.Bring your towel and join one of the fastest growing data communities. Welcome to our second-generation open source orchestration platform, a completely rethought approach to dataflow automation.
Powered by