1. Create a notification automation that fires on flow run completion.
-
Find the Automations page in the UI and click the
+
button. -
Define your trigger:
Add a tag that will filter out other people's flow runs, ideally you've tagged you deployment with your name, like in this example, I put
taylor
-
Define your action:
Use the block you created during the blocks quickstart.
-
Run a deployment (ensure that it meets the criteria set in your automation's trigger, e.g. the tags
pacc
andtaylor
)
2. Browse the events dashboard.
- See if you can spot the events related to the automation you just created:
- What about events related to your deployment?
- How about events relating to the blocks you created today?
- Click on the
Flow run
of a Block event to see when the method was called during the flow's execution: - Now simply click on the ✨ icon at the top right of the events line to return to the event feed. This action filters the feed to show only events related to the flow run from the page you were just viewing.
- Navigate to the automations page and create a new automation.
- Create a metrics trigger that alerts you after 10 minutes of a sustained success rate below 90% (referencing the average of the past day).
- Make the action a notification.
4. Declare and resolve a Prefect Incident
Incidents are formal declarations of disruptions to a workspace. With automations, activity in that workspace can be paused when an incident is created and resumed when it is resolved.
-
Find the
Incidents
page and click the+
button. -
Define a test incident, call it something like
your-name-pacc-test
and clickDeclare
: -
Add a test comment.
-
Navigate to the
Flow Runs
page and find a failed flow run. (Notice the AI Error Summaries) -
Click into a failed flow run, click on the three dots, and then click
Add to incident
-
Change the severity of the incident.
-
Note: Incidents are a more powerful feature when combined with automations:
Automations can be used for triggering an incident and for selecting actions to take when an incident is triggered. For example, a work pool status change could trigger the declaration of an incident, or a critical level incident could trigger a notification action.
To automatically take action when an incident is declared, set up a custom trigger that listens for declaration events.
{ "match": { "prefect.resource.id": "prefect-cloud.incident.*" }, "expect": [ "prefect-cloud.incident.declared" ], "posture": "Reactive", "threshold": 1, "within": 0 }
5. Advanced Automations: Create a custom trigger and compound actions
In this example, you'll create a custom trigger that results in an action of a toy webhook being called.
-
Find an block-based event in the event feed and click into the event details.
-
Click on the
Raw
tab to review the event's JSON values then click on the three dots at the top right and clickAutomate
.You'll see we can describe a custom triggering event using JSON:
Note: There are many things we can do to fine tune this custom trigger. For example, we could change the threshold from 1 to 2 if we want this event to occur twice before triggering any action. For more information on trigger grammar, check out these docs.
-
For the action select
Call a webhook
and define a webhook block.- First get a toy webhook endpoint at Webhook.site
- Copy your unique URL
- Back in Prefect's UI, select the action
Call a webhook
Add +
a webhook block, paste in your unique URL from Webhook.site, and clickCreate
. Alternatively, exit the automation screen, go to the Blocks page, and create the Web Hook block from there. Once created go back to the events feed to re-create the custom trigger.
-
Add another action to notify yourself about this.
-
Call your Automation something like
taylor-pacc-json-block-automation
and save. -
Run your flow that loads the block, something like:
from prefect import flow, task from prefect.blocks.system import JSON @task def load_block(): jb = JSON.load("taylor-pacc-json-block") my_dict = jb.value print(my_dict) @flow(log_prints=True) def load_block_flow(): load_block() if __name__ == "__main__": load_block_flow()
-
Verify that you got a notification email and verify that the webhook was called.