<@ULVA73B9P> I want to exclude manual flow run fro...
# ask-marvin
a
@Marvin I want to exclude manual flow run from automations is it possible to send alerts for only scheduled one
m
To achieve sending alerts only for scheduled flow runs and exclude manual ones, you can use Prefect's automations and triggers functionality. Both Prefect 2.x and 3.x support creating automations that can be triggered under specific conditions, such as a flow run's state change. ### Steps to Configure Automations 1. Access the Automations Page: Navigate to the Automations page in your Prefect Cloud workspace. 2. Create a New Automation: Click the "+" icon to create a new automation. 3. Configure Trigger Conditions: Set the conditions for when the automation should trigger. For example, you can specify triggers based on flow run state changes or custom criteria. 4. Set Actions: Define the actions to be executed when the trigger condition is met. This can include actions like sending notifications, running a deployment, etc. ### Specific Configuration 1. State Change Triggers: You can configure the trigger to only respond to scheduled flow runs instead of manual ones. This ensures that your automation only fires for flow runs that start as per a set schedule. 2. Custom Triggers: You can define custom event triggers if the pre-defined options do not fit your needs. For more detailed instructions, refer to the specific documentation for your Prefect version: - Prefect 2.x Automations Guide - Prefect 3.x Automations Triggers These guides provide comprehensive instructions on setting up and managing automations based on your requirements. Was this helpful? Let me know if you need more specific examples or if you have any other questions.
a
@Marvin I don't want get alert if I ran scheduled one manually
m
To avoid sending alerts for manually triggered flow runs, even if they were originally scheduled, you can utilize tagging or custom attributes to differentiate between scheduled and manually triggered runs. Here’s how you can approach this in Prefect: ### Suggested Approach: 1. Tagging Flow Runs: When you manually trigger a flow run, add a specific tag or custom attribute to indicate it was triggered manually. 2. Automations Based on Tags: Configure your automation to exclude flow runs with the "manual" tag or attribute from your alerts. ### Implementing in Prefect 2.x and 3.x #### Prefect 2.x 1. Add Tag on Manual Trigger: When triggering a flow run manually, include a custom tag:
Copy code
python
    from prefect import flow

    @flow
    def example_flow():
        print("Running Example Flow")

    if __name__ == "__main__":
        flow_run = example_flow.with_options(tags={"manual"})
        flow_run()
Alternatively, you can add custom metadata while creating the flow run from the CLI or API. 2. Exclude Tag in Automations: Set up an automation that triggers an alert unless the flow run includes the "manual" tag. For more details, refer to the Prefect 2.x Automations Guide. #### Prefect 3.x 1. Add Tag on Manual Trigger: Similar to Prefect 2.x, but you might need specific 3.x adaptations:
Copy code
python
    from prefect import flow

    @flow
    def example_flow():
        print("Running Example Flow")

    if __name__ == "__main__":
        from prefect.client import get_client
        from prefect.orion.schemas.filters import FlowRunFilter

        client = get_client()
        example_flow.run(tags={"manual"})
2. Configure Automation: Use the automations API or UI to create a trigger condition that excludes flow runs tagged as "manual". Here’s a detailed guide on Prefect 3.x Automations and Triggers and Custom Triggers. Following these steps ensures that your automations will only send alerts for scheduled runs and ignore any manual triggers, keeping your notifications relevant and precise. Let me know if you have more questions or need further assistance!