<@ULVA73B9P> In Prefect 3, can I have an automatio...
# ask-marvin
n
@Marvin In Prefect 3, can I have an automation that triggers everytime a flow ends, but trigger ANOTHER different automation if the flow failed 10 or more times? (without triggering the first automation). Basically, I want a trigger everytime a run ends (whatever the state) and a different trigger if a run has been retried for 10 times
m
thought for 254.3 seconds
Short answer: Yes—with a small caveat. Automations don’t support numeric comparisons (>=) in filters, so the cleanest way is to use two disjoint automations that never overlap. How to set it up in Prefect 3 (Cloud): - Automation A (run ended: Completed/Crashed): - Trigger type: Event - Expect: prefect.flow-run.Completed, prefect.flow-run.Crashed - Match: - prefect.resource.id: prefect.flow-run.* - This will fire for any flow run that finishes successfully or crashes (regardless of retry count). - Automation B (run failed with fewer than 10 attempts): - Trigger type: Event - Expect: prefect.flow-run.Failed - Match: - prefect.resource.id: prefect.flow-run.* - prefect.run-count: ["0","1","2","3","4","5","6","7","8","9"] - This covers “ordinary” failures and ensures your “general” notification fires for failures that have not crossed your threshold. - Automation C (run failed with 10 or more attempts): - Trigger type: Event - Expect: prefect.flow-run.Failed - Match: - prefect.resource.id: prefect.flow-run.* - prefect.run-count: ["10","11","12","13","14","15"] // extend as high as you need - This fires only for failures after many attempts and, because the filters are disjoint from Automation B, it will not trigger the “general” failure automation. Important details and limitations: - Attempt count is exposed as the label prefect.run-count on flow-run events. It’s a string label and filters only support exact match, glob, and negation—not numeric comparisons. That’s why we split the failure case into two automations with explicit value lists. - prefect.run-count is zero-based: - "0" = first attempt - "1" = first retry - … - "10" means the run has already been executed 11 times. If you truly want “failed 10 or more times,” you may want to start your “special” filter at "9". Let me know which interpretation you want and I’ll adjust the lists. - Automations do not suppress each other by priority—any automation whose filters match will fire. The above setup uses mutually exclusive filters so only one failure automation fires. Optional alternative (if you don’t want to list values): - You can detect heavy retrying earlier by triggering on prefect.flow-run.AwaitingRetry and using a threshold per run. For example: - Trigger: Event - Expect: prefect.flow-run.AwaitingRetry - Match: prefect.resource.id = prefect.flow-run.* - For each: prefect.resource.id - Threshold: 10 - Within: a large enough window for your retry cadence This alerts once a run has entered AwaitingRetry at least 10 times. It’s different from “final failure after 10+ attempts,” but avoids enumerating run-count values. Docs for reference: - Automations concepts - Cloud events and labels If you share how high your flows can retry (max attempts), I can give you ready-to-paste match lists for Automation C—and confirm whether your “10 or more” should start at run-count "9" or "10" based on your intent.