Charles Liu
09/21/2024, 7:56 AMMarvin
09/21/2024, 7:56 AMrun_deployment
function in Prefect, you first need to confirm which version of Prefect you are using since the method might differ between versions.
### Prefect 2.x
In Prefect 2.x, the run_deployment
function is part of the Prefect Core API. After running a deployment, you need to retrieve the corresponding flow run's result, which requires using the Prefect Client.
### Prefect 3.x
In Prefect 3.x, you can similarly run deployments and retrieve the state of the flow run to get the result.
Here’s an example for each version:
#### Prefect 2.x Example
1. Run the deployment:
python
from prefect.client import OrionClient
from prefect.deployments import run_deployment
deployment_id = "your_deployment_id_step"
deployment_params = {"param": "value"}
client = OrionClient()
# Run the deployment and get the flow run id
flow_run_id = await run_deployment(deployment_id, parameters=deployment_params)
# Retrieve the state of the flow run
state = await client.get_flow_run_state(flow_run_id)
result = state.result()
print(result)
#### Prefect 3.x Example
1. Run the deployment and get the state of the flow run:
python
from prefect.deployments import run_deployment
from prefect.client import get_client
deployment_name = "your_deployment_name"
deployment_params = {"param": "value"}
# Run the deployment
flow_run = await run_deployment(deployment_name, parameters=deployment_params)
# Obtain the state of the flow run
client = get_client()
state = await client.read_flow_run_state(flow_run.id)
result = state.result()
print(result)
Make sure to replace "your_deployment_id"
or "your_deployment_name"
with your actual deployment ID or name, and adjust deployment parameters accordingly.
For further details, you can refer to additional Prefect documentation:
- Prefect 2.x Deployment Guide
- Prefect 3.x Deployment Guide
If you encounter any specific issues or need refined information, feel free to ask!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