mira
12/05/2023, 6:25 AMMarvin
12/05/2023, 6:25 AM# Assume `body_string` is the parsed body-string of your webhook event
if 'specific_word' in body_string:
# Run your automation here
Please replace 'specific_word' with the actual word you want to check in the body-string. Also, make sure to replace the comment inside the if statement with the actual code of your automation.
For more information, you can refer to the Prefect's webhooks guide.mira
12/05/2023, 6:29 AMMarvin
12/05/2023, 6:32 AM"expect": ["prefect.flow-run.Failed"]
) for a specific deployment ("prefect.resource.id": "prefect.deployment.70cb25fe-e33d-4f96-b1bc-74aa4e50b761"
).
However, the current automation functionality does not support triggering based on the content of the event body string. The automation is designed to react to specific events and their associated metadata, not the content of the event body.
If you need to trigger an action based on the content of the event body, you might need to handle this in the flow itself, or in a separate service that listens to the webhook events and triggers the appropriate action based on the content of the event body.
For more information, you can refer to the Prefect's automation guide.Nate
12/05/2023, 6:43 AM» python examples/flows/on_event_body.py
╭──────────────────────────────────────────────────────────────────────────────────
│ Your deployments are being served and polling for scheduled runs! │
│ Deployments │
│ ┌──────────────────────────┐ │
│ │ downstream/on_event_body │ │
│ └──────────────────────────┘ │
│ To trigger any of these deployments, use the following command: │
│ │
│ $ prefect deployment run [DEPLOYMENT_NAME] │
│ │
│ You can also trigger your deployments via the Prefect UI: │
│ <https://app.prefect.cloud/account/xxx/workspace/xxx/deployments>
00:40:37.604 | INFO | prefect.flow_runs.runner - Runner 'runner-690f5a56-60b3-4eaa-9fb8-3b48ab49cf41' submitting flow run 'b58954e4-fea4-408b-a48e-5780014794bb'
00:40:37.749 | INFO | prefect.flow_runs.runner - Opening process...
00:40:37.757 | INFO | prefect.flow_runs.runner - Completed submission of flow run 'b58954e4-fea4-408b-a48e-5780014794bb'
00:40:39.457 | INFO | Flow run 'camouflaged-pigeon' - Downloading flow code from storage at '.'
00:40:39.971 | INFO | Flow run 'camouflaged-pigeon' - i was triggered!
00:40:40.097 | INFO | Flow run 'camouflaged-pigeon' - Finished in state Completed()
00:40:40.510 | INFO | prefect.flow_runs.runner - Process for flow run 'camouflaged-pigeon' exited cleanly.
Nate
12/05/2023, 6:45 AMmatch
on within the resource
instead of trying to do conditional stuff on the event payload
since you can add / match on whatever labels you want in the automation, also my use of the sdk for the trigger instead of yaml and my use of serve
for the deployment is arbitrary, could easily do this in prefect.yaml
as well
if you're wanting to react to a specific part of prefect.flow-run.Failed
- you may want to manually emit_event
from an on_failure
hook on the offending flowmira
12/05/2023, 8:34 AMmira
12/05/2023, 8:45 AMMarvin
12/05/2023, 8:46 AMmira
12/05/2023, 8:58 AMMarvin
12/05/2023, 8:59 AMbody
variable. The body
variable contains the entire body of the incoming HTTP request.
Here is an example of how you can do this:
json
{
"event": "my.event",
"resource": {
"prefect.resource.id": "my.resource",
"prefect.resource.name": "My Resource",
"my_parameter": "{{ body }}"
}
}
In this example, the my_parameter
resource parameter is assigned the full event payload body string.
Please note that the body
variable contains the body of the incoming HTTP request as a string. If the body was sent as JSON, you can convert it to a dictionary using the tojson
filter, like this: {{ body|tojson }}
.
For more information, you can refer to the Prefect's webhooks guide.mira
12/05/2023, 11:08 AM"unexpected character: line 6 column 50 (char 201)"
it seems that the webhook still tries to parse my xml msg ... how can i just access my message as string from out an event? should i use a static webhook? how can I pass the event payload body into my flow with an prefect automation?Marvin
12/05/2023, 11:09 AMjson
{
"match": {
"prefect.resource.id": "prefect.flow-run.*"
},
"match_related": {
"prefect.resource.id": "prefect.deployment.70cb25fe-e33d-4f96-b1bc-74aa4e50b761",
"prefect.resource.role": "deployment"
},
"for_each": [
"prefect.resource.id"
],
"after": [],
"expect": [
"prefect.flow-run.Failed"
],
"posture": "Reactive",
"threshold": 2,
"within": 10,
"actions": [
{
"type": "prefect.flow-run.create",
"config": {
"flow_id": "your-flow-id",
"parameters": {
"payload": "{{ body }}"
}
}
}
]
}
In this example, the payload
parameter of your flow will receive the entire XML payload as a string.
3. In your flow, you can then parse the XML payload as needed. There are many Python libraries available that can parse XML, such as xml.etree.ElementTree
and lxml
.
Please replace "your-flow-id"
with the actual ID of your flow.
For more information, you can refer to the Prefect's automation guide and webhooks guide.mira
12/05/2023, 11:46 AMMarvin
12/05/2023, 11:46 AM{{ event.payload.body }}
.
Here's the corrected automation configuration:
json
{
"match": {
"prefect.resource.id": "prefect.flow-run.*"
},
"match_related": {
"prefect.resource.id": "prefect.deployment.70cb25fe-e33d-4f96-b1bc-74aa4e50b761",
"prefect.resource.role": "deployment"
},
"for_each": [
"prefect.resource.id"
],
"after": [],
"expect": [
"prefect.flow-run.Failed"
],
"posture": "Reactive",
"threshold": 2,
"within": 10,
"actions": [
{
"type": "prefect.flow-run.create",
"config": {
"flow_id": "your-flow-id",
"parameters": {
"payload": "{{ event.payload.body }}"
}
}
}
]
}
In this example, the payload
parameter of your flow will receive the entire XML payload as a string.
Please replace "your-flow-id"
with the actual ID of your flow.
For more information, you can refer to the Prefect's automation guide and webhooks guide.mira
12/05/2023, 3:33 PM