https://prefect.io logo
Title
j

Joseph Thickpenny Ryan

02/06/2023, 5:54 PM
In the same vein of question, is there anywhere that I can get a list of event names that we can make triggers on?
w

Will Raphaelson

02/06/2023, 6:30 PM
Hey Joseph, you can make an api call to the events filter endpoint to list the events in your workspace. any event is fair game for a trigger. We’re currently working on a nice ui for visualizing and exploring events, so that should help with this moving forward. The events system is relatively new, would love to hop on a call if you feel you have any feedback based on working with it, especially the APIs. Let me know if you want to do a coffee or something.
sorry for the snag but this endpoint is being a bit flakey right now, the team is on it. sorry about that!
tried to get you a quick python snippet and realized it was erroring out.
j

Joseph Thickpenny Ryan

02/06/2023, 7:33 PM
I'll have a go with it, I'm looking at how I can generate some of these automations without using the UI, so I can put them in a codebase. If I have anything decent feedback I'll post something No worries on the endpoint / code snippet, I've got most of something written up anyway and won't be looking at it until tomorrow now anyway
I've had a go against the API, I managed to query the events endpoint but I've not been able to use the create automation endpoint as I just get validation errors (but not easily readable ones) As far as I can tell this blob meets the definition as per the api docs, @Will Raphaelson do you see anything wrong with this / are you able to provide me with a code snippet afterall?
{
    "name": "test",
    "trigger": {
        "after": [ "prefect.flow-run.Failed" ], 
        "posture": "Reactive",
        "threshold": 1,
    },
    "actions": [
        {
            "type": "send-notification",
            "block_document_id": "XXXXXXXX",
            "subject": "failure",
            "body": "failure"
        }
    ]
}
w

Will Raphaelson

02/07/2023, 4:40 PM
Hmm here’s one ive used in the past
AUTOMATION = {
    "name": "notification-test-3",
    "description": "notification",
    "trigger": {
    "match": {
        "prefect.resource.id": "prefect.flow-run.*"}, 
    "match_related": 
        {"prefect.resource.id": 
            ["prefect.flow.4914aee7-f66b-4410-a719-7f18dde2d583"], 
    "prefect.resource.role": "flow"}, 
    "after": [], 
    "expect": ["prefect.flow-run.Completed"], 
    "for_each": ["prefect.resource.id"], 
    "posture": "Reactive", 
    "threshold": 1, 
    "within": 10.0},
    "actions": [
            {"type": "send-notification",
             "block_document_id": "23f174d5-0a6e-440d-9965-4cd45b54d3d9",
             "subject": "yo",
             "body": mssg,
            },
        ],
        }
we need to publish some recipes. sorry about that. We’re about to open this up to configure these custom trigger definitions via json in the browser, so debugging them quickly will be easier.
j

Joseph Thickpenny Ryan

02/07/2023, 4:42 PM
Cheers, I'll have another go
w

Will Raphaelson

02/07/2023, 4:44 PM
i think for your case based on that blob above you can nix the match related, so
AUTOMATION = {
    "name": "notification-test-3",
    "description": "notification",
    "trigger": {
    "match": {
        "prefect.resource.id": "prefect.flow-run.*"}, 
    "match_related": {},
    "after": [], 
    "expect": ["prefect.flow-run.Completed"], 
    "for_each": ["prefect.resource.id"], 
    "posture": "Reactive", 
    "threshold": 1, 
    "within": 10.0},
    "actions": [
            {"type": "send-notification",
             "block_document_id": "23f174d5-0a6e-440d-9965-4cd45b54d3d9",
             "subject": "yo",
             "body": mssg,
            },
        ],
        }
j

Joseph Thickpenny Ryan

02/08/2023, 9:16 AM
Not sure what I was doing wrong, but I've got this working. Thanks Will!
w

Will Raphaelson

02/08/2023, 5:19 PM
glad to hear it!