Michael Schwartz
08/01/2025, 2:32 PM{
"id": "5a408bc9-1dcb-414c-8a0c-06cae59ef100",
"account": "1f68ce6c-568d-4d7a-ae99-9641099300bd",
"event": "cdf.publish_audited_tables",
"occurred": "2025-08-01T09:21:06.931Z",
"payload": {},
"received": "2025-08-01T09:21:07.120Z",
"related": [
{
"prefect.resource.id": "prefect.flow-run.0688c4b8-0084-7f68-8000-8817abb7c7f2",
"prefect.resource.role": "flow-run",
"prefect.resource.name": "encouraging-coot"
},
{
"prefect.resource.id": "prefect.task-run.51fc24db-de00-46e7-b02a-1db5044ecc13",
"prefect.resource.role": "task-run",
"prefect.resource.name": "bigeye_integrity_checks_and_publish-b9b"
},
{
"prefect.resource.id": "prefect.flow.5cf8010e-076a-40e3-9e73-a96a2e25a752",
"prefect.resource.role": "flow",
"prefect.resource.name": "build-prod"
}
],
"resource": {
"prefect.resource.id": "cdf"
},
"workspace": "8f854e6c-4fe7-49b7-860c-8f2e7973c905"
}
and this trigger automation
{
"type": "event",
"match": {},
"match_related": {
"prefect.resource.role": "flow-run"
},
"after": [],
"expect": [
"cdf.publish_audited_tables"
],
"for_each": [],
"posture": "Reactive",
"threshold": 1,
"within": 0
}
i'm i'm expecting this automation to occur only once but it happens 3 times, how to fixMarvin
08/01/2025, 2:32 PMMarvin
08/01/2025, 2:33 PMfor_each
property to group the evaluation:
json
{
"type": "event",
"match": {},
"match_related": {
"prefect.resource.role": "flow-run"
},
"expect": [
"cdf.publish_audited_tables"
],
"for_each": ["event"], // This will group by the event ID
"posture": "Reactive",
"threshold": 1,
"within": 60 // Optional: window in seconds to group matches
}
By adding "for_each": ["event"]
, the automation will be evaluated once per unique event, regardless of how many related resources match. This is the most reliable way to ensure single triggering in your case.
2. Alternatively, if you need to be more specific about which flow-run should trigger the automation, you could make the matching more precise:
json
{
"type": "event",
"match": {},
"match_related": {
"prefect.resource.role": "flow-run",
"prefect.resource.name": "encouraging-coot" // Match specific flow-run
},
"expect": [
"cdf.publish_audited_tables"
],
"posture": "Reactive",
"threshold": 1,
"within": 0
}
The first approach (using for_each
) is recommended as it's more robust and will continue to work even if flow run names change. It ensures the automation triggers exactly once per event, which seems to be what you're looking for.
Remember that the within
parameter is optional - if you set it to 0 (as in your original configuration), it means the automation will trigger immediately when the conditions are met. If you want to group matches within a time window, you can set it to a positive number of seconds.