<@ULVA73B9P> is there a way to define multiple tri...
# ask-marvin
r
@Marvin is there a way to define multiple triggers for a single automation?
m
Yes, you can define multiple triggers for a single automation in Prefect by using a composite trigger. Composite triggers allow you to create a trigger from multiple kinds of events and metrics through a compound or sequence trigger. These triggers are composed of a set of underlying event and metric triggers. For instance, if you want to create an automation that only runs after several different events have occurred, you can use a 'compound' trigger to combine multiple event triggers with the following structure:
Copy code
json
{
  "type": "compound",
  "require": "all",
  "within": 3600,
  "triggers": [
    {
      "type": "event",
      "posture": "Reactive",
      "expect": ["event_name"]
    },
    // Additional triggers can be added here
  ]
}
Using the
compound
trigger type, you specify that all included triggers must occur within a certain timeframe (here, one hour) for the automation to be executed. You can learn more about setting up composite triggers in the Prefect documentation here: Automations.
r
@Marvin does this look fine? i want this compound trigger to fire if either a flow run fails/crashes/times out or stays in pending for more than 15 minutes
Copy code
{
  "type": "compound",
  "require": "any",
  "within": 10,
  "triggers": [
    {
        "type": "event",
        "match": {
          "prefect.resource.id": "prefect.flow-run.*"
        },
        "match_related": {
          "prefect.resource.role": "tag",
          "prefect.resource.id": [
            "prefect.tag.pagerduty_automation:pd-sq-sqprefect-tests-stage"
          ]
        },
        "after": [
          "prefect.flow-run.Pending"
        ],
        "expect": [
          "prefect.flow-run.*"
        ],
        "for_each": [
          "prefect.resource.id"
        ],
        "posture": "Proactive",
    },
    {
        "type": "event",
        "match": {
          "prefect.resource.id": "prefect.flow-run.*"
        },
        "match_related": {
          "prefect.resource.id": [
            "prefect.tag.pagerduty_automation:pd-sq-sqprefect-tests-stage"
          ],
          "prefect.resource.role": "tag"
        },
        "after": [],
        "expect": [
          "prefect.flow-run.Crashed",
          "prefect.flow-run.TimedOut",
          "prefect.flow-run.Failed"
        ],
        "for_each": [
          "prefect.resource.id"
        ],
        "posture": "Reactive"
      }
  ]
}
m
Your message was too long by 51 tokens - please shorten it and try again. For reference, here's your message at the allowed limit:
does this look fine? i want this compound trigger to fire if either a flow run fails/crashes/times out or stays in pending for more than 15 minutes
```{ "type": "compound", "require": "any", "within": 10, "triggers": [ { "type": "event", "match": { "prefect.resource.id": "prefect.flow-run.*" }, "match_related": { "prefect.resource.role": "tag", "prefect.resource.id": [ "prefect.tag.pagerduty_automation:pd-sq-sqprefect-tests-stage" ] }, "after": [ "prefect.flow-run.Pending" ], "expect": [ "prefect.flow-run.*" ], "for_each": [ "prefect.resource.id" ], "posture": "Proactive", }, { "type": "event", "match": { "prefect.resource.id": "prefect.flow-run.*" }, "match_related": { "prefect.resource.id": [ "prefect.tag.pagerduty_automation:pd-sq-sqprefect-tests-stage" ], "prefect.resource.role": "tag" }, "after": [], "expect": [ "prefect.flow-run.Crashed",