Deployment-specific automation with flow run state template? #18757
-
When adding an automation with a flow run state template, one has to choose a flow but cannot select a specific deployment. Therefore the automation would apply to flow runs belonging to all deployments of a flow. In my case I need to run a specific deployment of my flow, based on the deployment to which the trigger flow run belongs. If I'm not mistaken, this is not possible right now. There may be fundamental reasons why that could not be. But if it's possible in principle, I think it would be a valuable addition to Prefect's automations. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
You should be able to go into the JSON tab in the UI's Automation builder and use programmatically, this should be possible the same way. is this helpful? |
Beta Was this translation helpful? Give feedback.
-
Hi @TheoMathurin! Prefect does support this, but you'll need to use a "Custom" trigger template. Expand the Evaulation Options accordion and select the deployment in the Filter for events related to multi-select form field. Here's a longer, more detailed explanation of @zzstoatzz's answer: A flow run state event will have "related" resources associated with it. An example of a flow run state change message will look something like this (with a few fields omitted):
Note the second resource in the related array that describes the deployment ID the event's resource is associated with. So, to build an automation to run another deployment based on an "upstream" deployment's flow status changing to completed, you can use the It would look something like this in your automation JSON configuration:
Then, select your deployment you want to run as the action. Here's a full automation YAML example you could use too: automations:
- name: Run downstream flow
description: Runs a downstream flow when the upstream flow completes
enabled: true
trigger:
type: event
posture: Reactive
expect:
- prefect.flow-run.Completed
match:
- prefect.resource.id: "prefect.flow-run.*"
match_related:
- prefect.resource.id: "prefect.deployment.<upstream-deployment-guid>"
threshold: 1
for_each:
- prefect.resource.id
actions:
- type: run-deployment
deployment_id: "<downstream-deployment-guid>"
parameters: {}
job_variables: {} Deploy this using Take a look at these resources for some more information: |
Beta Was this translation helpful? Give feedback.
-
Ok thanks! I had not looked at the custom automation builder. I have not yet tried but it should be ok then. As an aside, I realise that in the dropdown widgets in the custom builder, deployments appear with their short name, and not their full name ( Is it worth adding a feature request to change how deployments appear in these dropdowns, or is it such bad practice to name deployments in this manner that it should never happen? |
Beta Was this translation helpful? Give feedback.
hi @TheoMathurin
You should be able to go into the JSON tab in the UI's Automation builder and use
match_related
to restrict the trigger to deployments associated with the selected resource (e.g. flow)programmatically, this should be possible the same way.
is this helpful?