<@ULVA73B9P> I have the following automation trigg...
# ask-marvin
b
@Marvin I have the following automation trigger but it never triggers even when my flows are failing. What is wrong with it?
Copy code
{
  "type": "event",
  "match": {
    "prefect.resource.id": "prefect.flow-run.*"
  },
  "match_related": {
    "prefect.resource.name": [
      "*-extract"
    ],
    "prefect.resource.role": "flow"
  },
  "after": [],
  "expect": [
    "prefect.flow-run.Crashed",
    "prefect.flow-run.Failed"
  ],
  "for_each": [
    "prefect.resource.id"
  ],
  "posture": "Reactive",
  "threshold": 1,
  "within": 0
}
m
I found some useful insights regarding your automation trigger problem. 1. From the Prefect documentation, an automation trigger should react to a single event. The potential issue with your configuration is the
"within": 0
field. Typically,
within
should be set to a positive value representing the time window within which the events must occur. Here’s the relevant schema from the Prefect documentation: https://docs.prefect.io/latest/concepts/automations/ 2. There is a related issue on GitHub where a trigger with the
within
field fails. The error might not be directly applicable but indicates potential issues with the use of the
within
field. https://github.com/PrefectHQ/prefect/issues/14309 Try adjusting the
within
value to a positive integer representing an appropriate duration in seconds. If the issue persists, examine whether the events you expect (
"prefect.flow-run.Crashed"
and
"prefect.flow-run.Failed"
) are indeed occurring and match the resource criteria specified. For further reference, you can look into specific configurations and their proper usage: https://docs.prefect.io/latest/guides/state-change-hooks/ Make sure the other fields, such as
match
and
match_related
, are correctly specifying the required resources.
b
@Marvin I don’t think you are right. This works
Copy code
{
  "type": "event",
  "match": {
    "prefect.resource.id": "prefect.flow-run.*"
  },
  "match_related": {
    "prefect.resource.id": [
      "prefect.flow.96b40478-de20-4388-8961-9bb9b0189dd3",
      "prefect.flow.0b735bb9-2fb5-483b-8115-ff2ec3eaa913"
    ],
    "prefect.resource.role": "flow"
  },
  "after": [],
  "expect": [
    "prefect.flow-run.Crashed",
    "prefect.flow-run.Failed",
    "prefect.flow-run.TimedOut"
  ],
  "for_each": [
    "prefect.resource.id"
  ],
  "posture": "Reactive",
  "threshold": 1,
  "within": 0
}
even with
within
being 0. But the problem with the one just above is that I need to list all the flows 1 by 1 and I don’t want to do that. I want to check all the flows that have a name finishing with
-extract
m
Thank you for clarifying. You're right; the
within
field being
0
is acceptable. To ensure your automation trigger works without specifying each flow individually and instead matches flow names ending with
-extract
, you should adjust your
match_related
criteria correctly. Based on the documentation, it seems your approach should work, but perhaps there's a syntax issue with wildcards. Let's refine your configuration by ensuring the correct usage of wildcards:
Copy code
json
{
  "type": "event",
  "match": {
    "prefect.resource.id": "prefect.flow-run.*"
  },
  "match_related": {
    "prefect.resource.name": ["*-extract"],
    "prefect.resource.role": "flow"
  },
  "after": [],
  "expect": [
    "prefect.flow-run.Crashed",
    "prefect.flow-run.Failed"
  ],
  "for_each": [
    "prefect.resource.id"
  ],
  "posture": "Reactive",
  "threshold": 1,
  "within": 0
}
Ensure that: 1. The wildcard
*-extract
correctly matches the required flow names. 2. The `prefect.resource.role`:
flow
is appropriately set. If the primary issue persists, review the documentation for any caveats related to wildcard matching in
match_related
properties. For more detailed guidance, consult the Prefect Automations Documentation and verify your flow names and roles are suitable. Would you like me to explore more details on wildcard usage within Prefect automations?