Russell Brooks
05/28/2026, 10:10 AMMarvin
05/28/2026, 10:10 AMMarvin
05/28/2026, 10:12 AMautomation.yaml for Prefect 3.7.2 that alerts when a flow run in the default or backup work pool has been running for more than 2 hours.
yaml
name: "long-running-flow-run-alert"
description: "Notify when a flow run in default or backup work pools runs longer than 2 hours"
enabled: true
trigger:
type: event
posture: Proactive
after:
- prefect.flow-run.Running
expect:
- prefect.flow-run.Completed
- prefect.flow-run.Failed
- prefect.flow-run.Crashed
- prefect.flow-run.Cancelled
for_each:
- prefect.resource.id
match:
prefect.resource.id: "prefect.flow-run.*"
match_related:
prefect.resource.role: "work-pool"
prefect.resource.name:
- "default"
- "backup"
threshold: 1
within: 7200
actions:
- type: send-notification
block_document_id: "YOUR_NOTIFICATION_BLOCK_ID"
subject: "Long-running flow run detected"
body: |
Flow run {{ flow_run.name }} has been running for more than 2 hours.
Flow: {{ flow.name }}
Work pool: {{ work_pool.name }}
Flow run ID: {{ flow_run.id }}
State: {{ flow_run.state.name }}
A couple quick notes:
- within: 7200 is 2 hours in seconds
- posture: Proactive means “alert if the expected terminal event does not happen within the time window”
- for_each: [prefect.resource.id] ensures this evaluates per flow run
- match_related filters to flow runs associated with work pools named default or backup
To create it:
bash
prefect automation create --from-file automation.yaml
I verified that command exists in 3.x.
Relevant docs:
- Create automations
- Automations concept docs
If you want, I can also give you:
- a version that uses a specific notification block type like Slack/email/MS Teams, or
- a JSON version for prefect automation create --from-jsonRussell Brooks
05/28/2026, 10:17 AMMarvin
05/28/2026, 10:17 AMMarvin
05/28/2026, 10:18 AMyaml
prefect.resource.id: "prefect.flow-run.*"
and
yaml
prefect.resource.id: prefect.flow-run.*
Likewise:
yaml
- "default"
- "backup"
is equivalent to:
yaml
- default
- backup
Why people often quote them anyway
- To make it obvious the value is a string
- To avoid YAML interpreting special-looking values oddly in other cases
- To be safer when values contain characters like :, #, {}, [], *, or leading/trailing spaces
- For consistency across config files
In this automation, you can remove the quotes if you prefer. For example:
yaml
match:
prefect.resource.id: prefect.flow-run.*
match_related:
prefect.resource.role: work-pool
prefect.resource.name:
- default
- backup
One subtle note: YAML has special meaning for * at the start of a value because it can denote an alias. Your value is prefect.flow-run.*, so it’s generally fine unquoted.
So the short answer is: no, there’s no Prefect-specific reason they must be quoted here. It’s just style/defensive YAML.
If you want, I can rewrite the full automation.yaml in a more minimal unquoted style.