Ying Ting Loo
09/23/2024, 7:23 AMMarvin
09/23/2024, 7:24 AM{
"event": "model-update",
"resource": {
"prefect.resource.id": "product.models.{{ body.model_id }}",
"prefect.resource.name": "{{ body.friendly_name }}",
"run_count": "{{ body.run_count }}"
}
}
2. Use curl
to send data to Prefect's API endpoint:
curl -X POST <https://api.prefect.cloud/hooks/34iV2SFke3mVa6y5Y-YUoA> -d "model_id=adhoc" -d "run_count=10" -d "friendly_name=test-user-input"
3. Create automations directly from the event feed to trigger downstream deployments.
Further details: Automations Guide for Prefect 2.x and Concepts of Automations for Prefect 2.x.
### Prefect 3.x
Similarly, for Prefect 3.x, you can create webhooks to trigger deployments:
1. Define a webhook to respond to specific events:
curl -X POST <https://api.prefect.cloud/hooks/34iV2SFke3mVa6y5Y-YUoA> -d "model_id=adhoc" -d "run_count=10" -d "friendly_name=test-user-input"
2. Use event triggers to automate deployment runs:
python
from prefect import flow, serve
from prefect.events import DeploymentEventTrigger
@flow(log_prints=True)
def upstream_flow():
print("upstream flow")
@flow(log_prints=True)
def downstream_flow():
print("downstream flow")
if __name__ == "__main__":
upstream_deployment = upstream_flow.to_deployment(name="upstream_deployment")
downstream_deployment = downstream_flow.to_deployment(
name="downstream_deployment",
triggers=[
DeploymentEventTrigger(
expect={"prefect.flow-run.Completed"},
match_related={"prefect.resource.name": "upstream_deployment"},
)
],
)
serve(upstream_deployment, downstream_deployment)
3. Start the serve process to listen for scheduled runs:
python event_driven_deployments.py
Further details: Webhook Triggers for Prefect 3.x and Custom Triggers for Prefect 3.x.
Feel free to ask if you need more specific details!Ying Ting Loo
09/23/2024, 7:27 AMMarvin
09/23/2024, 7:27 AMPOST /flow_runs
endpoint provided by the Prefect API.
1. Create a flow run:
Make a POST request to http://<your-prefect-server-url>/api/flow_runs
with a JSON payload that specifies the flow_id
and other relevant parameters.
Example using `curl`:
curl -X POST http://<your-prefect-server-url>/api/flow_runs \
-H "Content-Type: application/json" \
-d '{
"flow_id": "<your-flow-id>",
"name": "my-flow-run"
}'
2. Identify your flow ID:
You can get the flow_id
from the Prefect server UI or through another API call to GET /flows
.
### Prefect 3.x
In Prefect 3.x, you follow similar steps but with updates to the API endpoint structure:
1. Create a flow run:
Make a POST request to http://<your-prefect-server-url>/api/flow_runs
with a JSON payload, similar to Prefect 2.x but ensuring compatibility with the new API structure.
Example using `curl`:
curl -X POST http://<your-prefect-server-url>/api/flow_runs \
-H "Content-Type: application/json" \
-d '{
"flow_id": "<your-flow-id>",
"name": "my-flow-run"
}'
2. Identify your flow ID:
The flow ID can be retrieved with an API call to GET /flows
or by checking the Prefect server UI.
Detailed instructions and API documentation can be found here:
- Prefect 2.x Flow Concept
- Prefect 3.x - Running Flows
Feel free to ask if you need more specific examples or further steps!