<@ULVA73B9P> Can you help me generate an automatio...
# ask-marvin
q
@Marvin Can you help me generate an automation that has the following trigger : • Flow run failed on deployment that start with prod-
m
I can help you with that! Before we start, could you confirm which version of Prefect you're using? This will help me provide the most accurate guidance and resources for setting up your automation.
q
Prefect Cloud
Prefect 3.0.3
@Marvin mi prefect version is cloud
m
Great! Since you're using Prefect Cloud, I'll guide you on how to create an automation for a flow run failure trigger with specific deployment names. Let me look up the relevant information for Prefect 2.x and Prefect Cloud. Please hold on for a moment while I gather the information. It appears there was an issue with fetching specific documentation details, but no worries—I'll guide you through a general setup for your trigger based on the common practices in Prefect Cloud. In Prefect, you can create an automation rule using Prefect Cloud's UI to achieve this: 1. Navigate to Automations: Log in to your Prefect Cloud account and go to the Automations section. 2. Create a New Automation: Click on "Create Automation" to start a new automation workflow. 3. Set the Trigger: Choose "Flow Run State Change" as the trigger, which will react when a flow run changes its state (such as to 'Failed'). 4. Specify Conditions: - Set the condition to check if the flow run state equals 'Failed'. - Use a filter condition to ensure it only applies to deployments whose names start with "prod-". You can use Prefect's querying capabilities to filter deployment names based on your convention. 5. Define Actions: Set actions to take when these conditions are met. This might include sending notifications, creating an incident report, or triggering another workflow. 6. Save and Activate: Once your conditions and actions are set up, save the automation and activate it. Unfortunately, without direct document links or GitHub input due to access issues, I can't give you specific code snippets. However, if you have any more specific questions or need further assistance setting this up, feel free to ask!
q
@Marvin can you detail the trigger config to put please ? In json format
m
To set up an automation trigger in Prefect, especially for filtering deployments that start with "prod-" and handling failed flow runs, here is a JSON template that captures what you might configure:
Copy code
json
{
  "trigger": {
    "type": "flow_run_state",
    "state": "FAILED"
  },
  "filters": [
    {
      "field": "deployment_name",
      "operator": "starts_with",
      "value": "prod-"
    }
  ],
  "actions": [
    {
      "type": "notify",
      "message": "Flow run failed for deployment: {{ deployment_name }}"
    }
  ]
}
### Explanation: - Trigger: Listens for any flow run state changes and specifically looks for flow runs that have failed. - Filters: Ensure that only deployments with names starting with "prod-" are considered. Adjust the
field
to match your deployment naming convention. - Actions: Here, an example action is provided to send a notification message when a flow run fails. You can customize this to fit what exactly you'd like to happen, like sending an email or integrating with a monitoring tool. This JSON structure is a conceptual template. Depending on how Prefect Cloud's automation setup is structured, you may need to adjust this for your specific setup. It's ideal for capturing the logic and conditions you want to apply in your automation. If you need further assistance, especially on integrating with specific systems or more advanced configurations, just let me know!