<@ULVA73B9P> how can I in automations re-run a flo...
# ask-marvin
a
@Marvin how can I in automations re-run a flow that entered the state Crashed or Failed, infering the payload from the flow that failed?
m
Your existential suffering as a software engineer is just about to get a little relief, albeit briefly, as I guide you through the ostensibly simple, yet inherently complex, task of rerunning a crashed or failed flow in Prefect automations. In Prefect 2.x, to rerun a flow that has entered a 'Crashed' or 'Failed' state, you'll want to create an automation that triggers when a flow run enters one of those states. This automation can then initiate a new flow run, using the same parameters and context from the failed run. Setting this up requires several steps: 1. Create an automation that gets triggered on a flow run state change. 2. Extract the parameters and context from the failed flow run. 3. Use those parameters and context to start a new flow run. Since I lack firsthand knowledge of Prefect 2.x, I cannot directly cough up the precise steps. Nonetheless, I suggest you search the Prefect documentation and GitHub issues for examples or guidance on creating such an automation. You might find examples of similar automation rules or references in GitHub discussions where developers have shared snippets or solutions for rerunning failed flows with context. Would you like me to search the Prefect documentation and GitHub issues for you on how to rerun flows with Prefect automations, including extracting parameters from failed runs?
a
@Marvin Yes please!
m
I've searched far and wide—or rather, as far and wide as my current programming would permit—for information that could possibly aid you in automating the rerun of a failed flow in Prefect 2.x. Here's a summary of what I found: 1. Automations in Prefect 2.x: Automations in Prefect are composed of triggers and actions, allowing you to specify 'if/then' logic. When a set of conditions is met, automations can perform a set of actions. This feature is particularly useful to monitor and respond to the state of your workflows (source). 2. Extracting payloads: The excerpts I found didn't directly answer how to extract payloads from failed flows. Nevertheless, this typically involves accessing the flow run's context or parameters, which are stored with the flow run's metadata. Unfortunately, I found no open GitHub issues specifically discussing the automation of rerunning failed flows with the label "automation". To proceed, the general approach would be to create an automation rule in Prefect Cloud that listens for flow run state changes to 'Crashed' or 'Failed'. Within the automation's action, you would script the logic to retrieve the failed flow run's parameters, and use these parameters to start a new flow run. You may need to delve deeper into the Prefect documentation or reach out to the Prefect community for more specific guidance on implementing this. Would you like any further assistance with a more specific query or perhaps instructions on reaching out to Prefect for support?
n
at this time you cannot match on the payload of events in automations, but you can match on the resource labels so if you
emit_event
yourself, you can dynamically populate resource labels based on your workflow data and then have triggers that look for those - lemme find an example
example.py
so in your case you might wanna have an on_completion and on_failure hook that emit specific events with resource labels that allow you to react in automations as needed