Geoff Irons
07/09/2025, 11:11 PMMarvin
07/09/2025, 11:11 PMMarvin
07/09/2025, 11:12 PMGeoff Irons
07/09/2025, 11:18 PM{
"type": "event",
"match": {
"prefect.resource.id": [
"prefect.work-queue.9376b608-5918-4d90-a4c8-64ebfb913312"
]
},
"match_related": {
"prefect.resource.role": "deployment"
},
"after": [],
"expect": [
"prefect.flow-run.TimedOut",
"prefect.flow-run.Cancelled",
"prefect.flow-run.Failed",
"prefect.flow-run.Cancelling",
"prefect.flow-run.Crashed"
],
"for_each": [
"prefect.resource.id"
],
"posture": "Reactive",
"threshold": 1,
"within": 0
}
An example event that I expected to be matched by this trigger, but was not, is:
{
"id": "0197ed7b-c021-79ae-9916-986a70f93c57",
"account": "9b6bc821-21ac-425c-9a22-ddb1e1df5d59",
"event": "prefect.task-run.Failed",
"occurred": "2025-07-09T04:39:59.777Z",
"payload": {
"intended": {
"from": "RUNNING",
"to": "FAILED"
},
"initial_state": {
"type": "RUNNING",
"name": "Running",
"message": "",
"state_details": {}
},
"validated_state": {
"type": "FAILED",
"name": "Failed",
"message": "Task run encountered an exception PolygonOutOfBoundsError",
"state_details": {
"retriable": false
},
"data": null
},
"task_run": {
"name": "check_polygons_within_boundary-af7",
"task_key": "check_polygons_within_boundary-539bf9ba",
"dynamic_key": "af70ba9d-46a9-468b-ba55-d39d31ae1312",
"empirical_policy": {
"max_retries": 0,
"retry_delay_seconds": 0,
"retries": 0,
"retry_delay": 0
},
"tags": [],
"labels": {},
"task_inputs": {
"polygons": [
{
"input_type": "task_run",
"id": "0197ed7b-be43-7b6f-95c6-e234f75950c3"
},
{
"input_type": "task_run",
"id": "0197ed7b-bf5c-7973-8ade-ae7c1a813776"
}
],
"project_boundary": [
{
"input_type": "task_run",
"id": "0197ed7b-bf5c-7973-8ade-ae7c1a813776"
}
]
},
"run_count": 1,
"flow_run_run_count": 1,
"expected_start_time": "2025-07-09T04:39:59.737920Z",
"start_time": "2025-07-09T04:39:59.761357Z",
"end_time": "2025-07-09T04:39:59.777696Z",
"total_run_time": 0.016339
}
},
"received": "2025-07-09T04:39:59.882Z",
"related": [
{
"prefect.resource.id": "prefect.flow-run.0686df29-d9b2-746c-8000-713f0222ae4c",
"prefect.resource.role": "flow-run",
"prefect.resource.name": "ccu_v2_flow-CCP397/ccu_evidence_flow"
},
{
"prefect.resource.id": "prefect.flow.87b4ea72-7c1a-4ec6-9059-ca20df1f6872",
"prefect.resource.role": "flow",
"prefect.resource.name": "ccu_evidence_flow"
}
],
"resource": {
"prefect.resource.id": "prefect.task-run.0197ed7b-bff9-7c7f-99e0-62468bd572ca",
"prefect.resource.name": "check_polygons_within_boundary-af7",
"prefect.state-message": "Task run encountered an exception PolygonOutOfBoundsError",
"prefect.state-name": "Failed",
"prefect.state-timestamp": "2025-07-09T04:39:59.777696+00:00",
"prefect.state-type": "FAILED",
"prefect.orchestration": "client"
},
"workspace": "28c0ee61-44f8-4ac0-802a-d15b833d1c28"
}
Marvin
07/09/2025, 11:18 PMMarvin
07/09/2025, 11:19 PMresource
or related
fields. This is expected behavior - work queue information is only available at the flow-run level.
2. To properly catch both task and flow failures for a specific work queue, you'll need to:
a. Either modify your trigger to watch for both task and flow events
b. Or rely on flow-run failure events only (since a flow run will typically fail when its tasks fail)
I recommend option (b) as it's cleaner and will avoid duplicate notifications. Your current trigger configuration is correct for this approach - you just need to ensure that:
1. The work queue ID is correctly associated with the deployment
2. The flow is configured to fail when tasks fail (this is the default behavior)
If you want to verify the work queue association, you can check the deployment details in the UI or use the CLI command:
bash
prefect deployment inspect <deployment-name>
This will show you which work queue the deployment is using and confirm whether it matches the ID in your trigger configuration.Geoff Irons
07/09/2025, 11:22 PM{
"id": "0686df2a-0511-7f44-8000-89a2ce4d2680",
"account": "9b6bc821-21ac-425c-9a22-ddb1e1df5d59",
"event": "prefect.flow-run.Failed",
"occurred": "2025-07-09T04:40:00.316Z",
"payload": {
"intended": {
"from": "RUNNING",
"to": "FAILED"
},
"initial_state": {
"type": "RUNNING",
"name": "Running"
},
"validated_state": {
"type": "FAILED",
"name": "Failed",
"message": "Flow run encountered an exception: PolygonOutOfBoundsError"
}
},
"received": "2025-07-09T04:40:00.446Z",
"related": [
{
"prefect.resource.id": "prefect.flow.4b57357e-7e47-40d2-be82-4ca942170e94",
"prefect.resource.role": "flow",
"prefect.resource.name": "ccu_v2_flow"
},
{
"prefect.resource.id": "prefect.deployment.3e1ed183-9f82-4976-9f21-49bdb7bd028a",
"prefect.resource.role": "deployment",
"prefect.resource.name": "prod",
"prefect.deployment.version-id": "0685b40d-837e-7a64-8000-4b12162e6529",
"prefect.deployment.version-type": "vcs:bitbucket",
"prefect.deployment.version": "e41de1ad"
},
{
"prefect.resource.id": "prefect.work-queue.9376b608-5918-4d90-a4c8-64ebfb913312",
"prefect.resource.role": "work-queue",
"prefect.resource.name": "prod"
},
{
"prefect.resource.id": "prefect.work-pool.3c008ba7-129a-4ae3-813a-284d524d2fd5",
"prefect.resource.role": "work-pool",
"prefect.resource.name": "default-worker-pool-prefect-v3",
"prefect.work-pool.type": "ecs"
},
{
"prefect.resource.id": "prefect.tag.CCP397",
"prefect.resource.role": "tag"
},
{
"prefect.resource.id": "prefect.tag.ccu_v2_flow",
"prefect.resource.role": "tag"
},
{
"prefect.resource.id": "prefect.tag.prod",
"prefect.resource.role": "tag"
},
{
"prefect.resource.id": "prefect-cloud.user.029e9a92-833a-44e7-b3c0-f8b16abf3c40",
"prefect.resource.role": "creator",
"prefect.resource.name": "ml-teamcarboncropnz"
}
],
"resource": {
"prefect.resource.id": "prefect.flow-run.0686df11-21f0-7a7e-8000-ea8a126b7c53",
"prefect.resource.name": "ccu_v2_flow-CCP397",
"prefect.state-message": "Flow run encountered an exception: PolygonOutOfBoundsError",
"prefect.state-name": "Failed",
"prefect.state-timestamp": "2025-07-09T04:40:00.316910+00:00",
"prefect.state-type": "FAILED"
},
"workspace": "28c0ee61-44f8-4ac0-802a-d15b833d1c28"
}
Marvin
07/09/2025, 11:22 PMMarvin
07/09/2025, 11:23 PMrelated
array, your trigger might not be matching it correctly. Let's try modifying your trigger configuration slightly:
json
{
"type": "event",
"match": {
"prefect.resource.id": [
"prefect.work-queue.9376b608-5918-4d90-a4c8-64ebfb913312"
]
},
"match_related": {
"prefect.resource.role": "work-queue" // Changed from "deployment" to "work-queue"
},
"expect": [
"prefect.flow-run.TimedOut",
"prefect.flow-run.Cancelled",
"prefect.flow-run.Failed",
"prefect.flow-run.Cancelling",
"prefect.flow-run.Crashed"
],
"for_each": [
"prefect.resource.id"
],
"posture": "Reactive",
"threshold": 1,
"within": 0
}
The key changes:
1. Changed match_related.prefect.resource.role
to "work-queue"
since we're trying to match based on the work queue
2. Kept the work queue ID in the match
section
If this still doesn't work, there's one more variation we could try:
json
{
"type": "event",
"match": {},
"match_related": {
"prefect.resource.id": "prefect.work-queue.9376b608-5918-4d90-a4c8-64ebfb913312",
"prefect.resource.role": "work-queue"
},
"expect": [
"prefect.flow-run.TimedOut",
"prefect.flow-run.Cancelled",
"prefect.flow-run.Failed",
"prefect.flow-run.Cancelling",
"prefect.flow-run.Crashed"
],
"for_each": [
"prefect.resource.id"
],
"posture": "Reactive",
"threshold": 1,
"within": 0
}
This moves the work queue matching entirely into the match_related
section, which might be more appropriate since the work queue appears in the related
array of the event.
Could you try one of these modified configurations and let me know if it resolves the issue? Also, it might be worth creating a GitHub issue about this behavior, as it seems like the documentation could be clearer about how match
and match_related
interact with resources in the event's related
array.Geoff Irons
07/09/2025, 11:38 PMMarvin
07/09/2025, 11:38 PMMarvin
07/09/2025, 11:39 PMpython
from prefect.client import get_client
async with get_client() as client:
# Get events for the last hour
events = await client.read_events(
limit=100,
event_filter={"occurred": {"after": "1h"}}
)
# Group events by resource type
event_types_by_resource = {}
for event in events:
resource_type = event.resource.type
event_type = event.event
if resource_type not in event_types_by_resource:
event_types_by_resource[resource_type] = set()
event_types_by_resource[resource_type].add(event_type)
Common event types include:
1. Flow Run Events:
- prefect.flow-run.Completed
- prefect.flow-run.Failed
- prefect.flow-run.Running
- prefect.flow-run.Scheduled
- prefect.flow-run.Pending
- prefect.flow-run.Crashed
- prefect.flow-run.Cancelling
- prefect.flow-run.Cancelled
2. Task Run Events:
- prefect.task-run.Completed
- prefect.task-run.Failed
- prefect.task-run.Running
3. Deployment Events:
- prefect.deployment.Created
- prefect.deployment.Updated
4. Work Queue Events:
- prefect.work-queue.Paused
- prefect.work-queue.Resumed
5. Work Pool Events:
- prefect.work-pool.Created
- prefect.work-pool.Updated
- prefect.work-pool.Deleted
The best practice for creating automations is to:
1. First observe the specific events you want to react to in the UI's Events page
2. Note the exact event names and resource structures
3. Create your automation trigger based on these observed events
This ensures you're working with actual events that exist in your system rather than theoretical ones that might not be emitted.
Would you like me to provide more specific details about any particular resource type's events?Geoff Irons
07/09/2025, 11:41 PM{
"type": "event",
"match": {
"prefect.resource.id": [
"prefect.work-queue.9376b608-5918-4d90-a4c8-64ebfb913312"
]
},
"match_related": {
"prefect.resource.role": "work-queue"
},
"after": [],
"expect": [
"prefect.flow-run.Cancelled",
"prefect.flow-run.Crashed",
"prefect.flow-run.TimedOut",
"prefect.flow-run.Failed",
"prefect.flow-run.Cancelling"
],
"for_each": [
"prefect.resource.id"
],
"posture": "Reactive",
"threshold": 1,
"within": 0
}
But it is still not seeing any eventsMarvin
07/09/2025, 11:41 PMMarvin
07/09/2025, 11:41 PMrelated
array as:
json
{
"prefect.resource.id": "prefect.work-queue.9376b608-5918-4d90-a4c8-64ebfb913312",
"prefect.resource.role": "work-queue",
"prefect.resource.name": "prod"
}
2. The flow run itself is the primary resource in the event, not the work queue. This means we need to modify our approach.
Try this modified trigger configuration:
json
{
"type": "event",
"match": {},
"match_related": {
"prefect.resource.id": [
"prefect.work-queue.9376b608-5918-4d90-a4c8-64ebfb913312"
]
},
"expect": [
"prefect.flow-run.TimedOut",
"prefect.flow-run.Cancelled",
"prefect.flow-run.Failed",
"prefect.flow-run.Cancelling",
"prefect.flow-run.Crashed"
],
"for_each": [
"prefect.resource.id"
],
"posture": "Reactive",
"threshold": 1,
"within": 0
}
Key changes:
1. Moved the work queue ID matching entirely to match_related
since it's in the related
array
2. Removed the prefect.resource.role
constraint as it might be redundant (the ID already specifies it's a work queue)
3. Empty match
object since we're not matching against the primary resource
If this still doesn't work, we could try one more variation that matches against the flow run ID pattern:
json
{
"type": "event",
"match": {
"prefect.resource.id": "prefect.flow-run.*"
},
"match_related": {
"prefect.resource.id": [
"prefect.work-queue.9376b608-5918-4d90-a4c8-64ebfb913312"
]
},
"expect": [
"prefect.flow-run.TimedOut",
"prefect.flow-run.Cancelled",
"prefect.flow-run.Failed",
"prefect.flow-run.Cancelling",
"prefect.flow-run.Crashed"
],
"for_each": [
"prefect.resource.id"
],
"posture": "Reactive",
"threshold": 1,
"within": 0
}
This explicitly states we're looking for flow run events (prefect.flow-run.*
) that are related to our specific work queue.
Could you try these configurations and let me know if either works? Also, it might be worth checking the automation's history in the UI to see if it's receiving the events but not triggering for some other reason.