MarcoM
07/25/2024, 9:19 AMMarvin
07/25/2024, 9:19 AMMarcoM
07/25/2024, 9:22 AMMarvin
07/25/2024, 9:23 AMpython
from prefect import flow
@flow(name="process_event_data")
def process_event_data(event_param: str):
print(f"Received event parameter: {event_param}")
if __name__ == "__main__":
process_event_data("example")
2. Deployment YAML with Jinja Templating:
Create a deployment YAML file where we specify the parameters using Jinja templating.
`deployment.yaml`:
yaml
name: process_event_data_deployment
version: 1
schedule:
cron: "0 0 * * *"
flow:
path: flow.py
entrypoint: process_event_data
parameters:
event_param: "{{ event.param }}"
triggers:
- enabled: true
match:
prefect.resource.id: prefect.flow-run.*
expect:
any:
- key: "event.param"
3. Trigger the Flow with an Event:
Use a webhook or another method to send an event that triggers the flow and passes attributes. Here, we simulate sending a webhook.
sh
curl -X POST <https://api.prefect.cloud/hooks/your-webhook-id> -d "param=event_value"
### Summary:
- Flow executes and logs the passed event parameter.
- Deployment YAML uses Jinja templating to substitute the event attribute into the parameter.
### Resources:
For more detailed information, refer to the complete Prefect Deployment Guide and Prefect Automations Guide.