Kartik
11/06/2025, 12:37 PMMarvin
11/06/2025, 12:37 PMMarvin
11/06/2025, 12:55 PMdeployments:
- name: your-deployment-name
entrypoint: path/to/flow.py:your_flow
# ... other deployment settings ...
triggers:
- type: event
enabled: true
posture: Proactive
after:
- prefect.flow-run.Running
expect:
- prefect.flow-run.Completed
- prefect.flow-run.Failed
- prefect.flow-run.Crashed
for_each:
- prefect.resource.id
threshold: 1
within: 30
actions:
- type: cancel-flow-run
Notes
- This is an event trigger with Proactive posture: it fires when none of the expected terminal events appear within 30 seconds after a run enters Running.
- for_each: ["prefect.resource.id"] ensures evaluation per run.
- actions: [{ type: cancel-flow-run }] cancels the stuck run.
About naming (CANCEL_LONG_RUNS)
- Deployment triggers in prefect.yaml cannot be named. If you specifically need a named, reusable automation called CANCEL_LONG_RUNS that can apply across deployments, create a standalone automation instead (via the UI). You can use a definition like this in the UI:
name: CANCEL_LONG_RUNS
description: Cancel flow runs that stay Running for more than 30s
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
for_each:
- prefect.resource.id
threshold: 1
within: 30
# Optional: add match/match_related here to scope to a specific flow or deployment
actions:
- type: cancel-flow-run
Clarification
- When you say “flow run X”, do you mean:
- Only runs of a specific deployment or flow?
- Or all runs across your workspace?
If it’s a single deployment, the prefect.yaml deployment trigger above is the simplest path. If it’s broader, a standalone automation (with filters) is better.
Docs for reference
- Event triggers (Proactive, after/expect/within): Event triggers
- Deployment triggers in prefect.yaml: Creating deployment triggers
- Creating standalone automations: Creating automations