Florent VanDeMoortele
09/19/2024, 12:46 PMMarvin
09/19/2024, 12:46 PMpython
from prefect.client import OrionClient
import asyncio
async def trigger_deployment(deployment_id, parameters):
async with OrionClient() as client:
await client.create_flow_run_from_deployment(deployment_id=deployment_id, parameters=parameters)
deployment_id = "your_deployment_id_here"
parameters = {} # any parameters needed for the deployment
asyncio.run(trigger_deployment(deployment_id, parameters))
Replace "your_deployment_id_here"
with the actual deployment ID you wish to trigger. The parameters
dictionary contains any parameters required by your deployment.
For more detailed information based on your Prefect version, check out the links provided. If you need further assistance or have specific questions regarding the example, feel free to ask!Florent VanDeMoortele
09/19/2024, 2:31 PMMarvin
09/19/2024, 2:31 PMsh
curl -X POST <https://api.prefect.cloud/hooks/YOUR_WEBHOOK_ID> \
-d "model_id=adhoc_model" \
-d "run_count=10" \
-d "friendly_name=test_input"
### Step 2: Define the Event Payload
Define the structure of the events that you will send to the webhook:
json
{
"event": "model-update",
"resource": {
"prefect.resource.id": "product.models.{{ body.model_id }}",
"prefect.resource.name": "{{ body.friendly_name }}",
"run_count": "{{body.run_count}}"
}
}
This JSON specifies that the webhook will create dynamic events using the provided data.
### Step 3: Automate Deployment in Prefect Cloud
In Prefect Cloud, configure an automation that will trigger a deployment based on the custom event created by the webhook. You can do this through the Prefect UI by following these steps:
1. Go to the Automations section in the Prefect UI.
2. Create a new automation and specify the custom event (e.g., model-update
) as the trigger.
3. Define the deployment to be triggered by this event in your automation configuration.
For more detailed information, refer to Prefect's automations documentation:
- Automations Guide: Automations in Prefect v2
- Event Triggers: Event Triggers in Prefect v2
If you have any other questions or need further assistance, feel free to ask!