Hey Folks, question about SLAs - is it possible to...
# ask-community
m
Hey Folks, question about SLAs - is it possible to trigger a flow run in case a certain flow run fails ?
Our use case is we want to run a “clean up flow” run if a given flow run fails …
Using a flow state handler is not ideal for us since the state handler will not run in case the flow run fails due to resource exhaustion
a
hey, yes that’s definitely possible and there are several ways how you could approach that. Are you on Prefect Cloud?
@Marwan Sarieddine regarding this point:
in case the flow run fails due to resource exhaustion
if your infrastructure crashes in the middle of a flow run, then it’s possible that the Flow’s heartbeat dies with it. In this scenario, it would be much more difficult to take action based on failure since the backend may think that your flow run is still in progress. This is also hard to answer without knowing your infrastructure, because it heavily dependent on where and how you run and configure your agent, run config, etc.
m
Hi @Anna Geller - Yes I am on prefect cloud but I don’t see creating a flow run as a possible action under the automations tab Please see the attached screenshot
I specifically mean under actions I only sending message actions …
Does that mean I need to create a custom action which “creates a flow run” ? I thought it would be one of the default options available
A bit about our infra - we are running a kubernetes agent and a DaskExecutor on AWS EKS
a
You’re right, this is not yet under Automations in the UI, but it should be added in the future, there is an open PR for it.
m
I see - thanks for confirming
is there a graphql snippet you can share that would create this action ? (that would be nice if it is something readily available)
a
There is a “create_action” mutation but I don’t know atm how the query would need to look like.
z
Copy code
mutation {
  create_action(input: {config: {create_flow_run: {flow_group_id: "..."}}}) {
    id
  }
}
upvote 1
If you use the IAPI in the UI you can see all of the options for the config
Copy code
flow_group_id: UUID!

The flow group id to create a flow run for
parameters: JSON

Optional parameters to pass to the flow run
in_seconds: Int

An optional amount of time to wait before starting the flow run
run_name: String

An optional name for the flow run
labels: [String]

An optional list of labels for the flow run
idempotency_key: String

An optional key to prevent duplicate runs from being created
Once you’ve got an
action_id
, you can create a hook to the relevant event with
create_flow_sla_failed_hook
or
create_flow_run_state_changed_hook
🙏 1
m
Hi @Zanie - thank you !
z
You can also set parameters for the action to template fields from the event, e.g.
{"foo": "foo-value", "failed_flow_run": "{flow_run_id}"}
You’re welcome
🙏 1