Skip to content

Commit

Permalink
Adds overview page for Automate section and updates content for v3 (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
discdiver committed Jul 7, 2024
1 parent fb3863b commit d3ff0ec
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 40 deletions.
13 changes: 13 additions & 0 deletions docs/3.0rc/automate/automate-overview.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
title: Automate overview
description: Learn how to automate workflows with Prefect.
---

This **Automate** section explains how create workflows that run automatically and respond to events.

- [Schedule flow runs](/3.0rc/automate/add-schedules/) explains how to schedule flow runs for specific times or intervals.
- [Track activity through events](/3.0rc/automate/events/events/) discusses how to observe events that create a record of activity.
- [Trigger actions on events](/3.0rc/automate/events/automations-triggers/) shows how to use events to trigger actions.
- [Define custom event triggers](/3.0rc/automate/events/custom-triggers/) discusses advanced trigger options.
- [Receive events with webhooks](/3.0rc/automate/events/webhook-triggers/) explains how to use webhooks to receive events from external systems with Prefect cloud.
- [Manage incidents](/3.0rc/automate/incidents/) show how Prefect Cloud can help identify, resolve, and document issues in mission-critical workflows.
21 changes: 6 additions & 15 deletions docs/3.0rc/automate/events/automations-triggers.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,14 @@ title: Trigger actions on events
description: Automations provide a flexible and powerful framework for automatically taking action in response to events.
---

Automations are a Prefect Cloud feature that enable you to configure [actions](#actions) that execute automatically based on
[trigger](#triggers) conditions.
Automations enable you to configure [actions](#actions) that execute automatically based on [trigger](#triggers) conditions.

Potential triggers include the occurrence of events from changes in a flow run's state—or the absence of such events.
You can even define your own custom trigger to fire based on an [event](/3.0rc/automate/events/) created from a
webhook or a custom event defined in Python code.
You can define your own custom trigger to fire based on a custom [event](/3.0rc/automate/events/custom-triggers/) defined in Python code.
With Prefect Cloud you can even create [webhooks](/3.0rc/automate/events/webhook-triggers/) that can receive data for use in actions.

Actions include starting flow runs, pausing schedules, and sending custom notifications.

## Prerequisites

- Python installed
- Prefect [installed](/3.0rc/get-started/install/)
- Authenticated to a [Prefect Cloud workspace](/3.0rc/get-started/quickstart/#step-2-connect-to-prefects-api/)
- A [work pool](/3.0rc/deploy/infrastructure-concepts/work-pools/) set up to handle the deployments

## Create an automation

On the **Automations** page, select the **+** icon to create a new automation. You'll be prompted to configure:
Expand Down Expand Up @@ -359,9 +351,9 @@ You can access properties of the underlying flow run objects including:

In addition to its native properties, each object includes an `id` along with `created` and `updated` timestamps.

The `flow_run|ui_url` token returns the URL to view the flow run in Prefect Cloud.
The `flow_run|ui_url` token returns the URL to view the flow run in the UI.

Heres an example for something relevant to a flow run state-based notification:
Here's an example relevant to a flow run state-based notification:

```
Flow run {{ flow_run.name }} entered state {{ flow_run.state.name }}.
Expand Down Expand Up @@ -512,8 +504,7 @@ run in response to an event.
Create an automation to kick off a deployment instead of a notification. Explore how to programmatically create this
automation with Prefect's REST API.

See the [REST API documentation](https://docs.prefect.io/latest/api-ref/rest-api/#interacting-with-the-rest-api) as a
reference for interacting with the Prefect Cloud automation endpoints.
See the [REST API documentation](https://docs.prefect.io/latest/api-ref/rest-api/#interacting-with-the-rest-api) as a reference for interacting with the automation endpoints.

Create a deployment to kick off some work based on how long a flow is running. For example, if the `build_names` flow
takes too long to execute, you can kick off a deployment with the same `build_names` flow, but replace the `count` value
Expand Down
48 changes: 24 additions & 24 deletions docs/3.0rc/automate/events/events.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ description: An event is a notification of a change, creating a history of activ

Events can represent API calls, state transitions, or changes in your execution environment or infrastructure.

Events power several features in Prefect Cloud, including flow run logs, audit logs, and automations.
Events power several features, including flow run logs and automations.
In Prefect Cloud, events power [audit logs](/3.0rc/manage/cloud/manage-users/audit-logs/).

Events enable observability into your data stack through the [event feed in the UI](#events-in-the-cloud-ui) and the
configuration of Prefect's reactivity through [automations](/3.0rc/automate/events/automations-triggers/).
Expand Down Expand Up @@ -47,47 +48,46 @@ You can also send events to the Prefect
### Emit custom events from Python code

The Prefect Python SDK provides an `emit_event` function that emits a Prefect event when called. You can call
`emit_event` inside or outside of a task or flow. For example, running this code emits an event to Prefect Cloud,
which validates and ingests the event data:
`emit_event` inside or outside of a task or flow. For example, running this code emits an event to the Prefect API, which validates and ingests the event data:

```python
from prefect.events import emit_event


def some_function(name: str="kiki") -> None:
print(f"hi {name}!")
emit_event(event=f"{name}.sent.event!", resource={"prefect.resource.id": f"coder.{name}"})

some_function()

if __name__ == "__main__":
some_function()
```

You must pass `emit_event` two arguments: `event`, the name of the event, and `resource={"prefect.resource.id": "my_string"}`,
the resource ID.
`emit_event` requires two arguments: `event`, the name of the event, and `resource={"prefect.resource.id": "my_string"}`, the resource ID.

To get data into an event for use in an automation action, specify a dictionary of values for the `payload` parameter.

### Emit events through webhooks

Prefect Cloud offers [programmable webhooks](/3.0rc/automate/events/webhook-triggers/) to receive HTTP requests
from other systems and translate them into events within your workspace. Webhooks can emit
[pre-defined static events](/3.0rc/automate/events/webhook-triggers/#static-webhook-events),
dynamic events that [use portions of the incoming HTTP request](/3.0rc/automate/events/webhook-triggers/#dynamic-webhook-events),
or events derived from [CloudEvents](/3.0rc/automate/events/webhook-triggers/#accepting-cloudevents).

Events emitted from any source appear in the event feed, where you can visualize activity in context and configure
[automations](/3.0rc/automate/events/automations-triggers/) to react to the presence or absence of events in the future.
from other systems and translate them into events within your workspace.
Webhooks can emit [pre-defined static events](/3.0rc/automate/events/webhook-triggers/#static-webhook-events),
dynamic events that [use portions of the incoming HTTP request](/3.0rc/automate/events/webhook-triggers/#dynamic-webhook-events), or events derived from [CloudEvents](/3.0rc/automate/events/webhook-triggers/#accepting-cloudevents).

## Resources

Every event has a primary resource, which describes the object that emitted an event. Resources are used as quasi-stable
identifiers for sources of events, and are constructed as dot-delimited strings, for example:
Every event has a primary resource, which describes the object that emitted an event.
Resources are used as quasi-stable identifiers for sources of events, and are constructed as dot-delimited strings.
For example:

```
prefect-cloud.automation.5b9c5c3d-6ca0-48d0-8331-79f4b65385b3.action.0
acme.user.kiki.elt_script_1
prefect.flow-run.e3755d32-cec5-42ca-9bcd-af236e308ba6
```

Resources can optionally have additional arbitrary labels which can be used in event aggregation queries, such as:
Resources can optionally have additional arbitrary labels which can be used in event aggregation queries.
For example:

```json
"resource": {
Expand All @@ -96,8 +96,9 @@ Resources can optionally have additional arbitrary labels which can be used in e
}
```

Events can optionally contain related resources, used to associate the event with other resources, such as in the case
that the primary resource acted on or with another resource:
Events can optionally contain related resources, used to associate the event with other resources.
For example, a primary resource can act on or with another resource.
Here is an example of a related resource:

```json
"resource": {
Expand All @@ -114,10 +115,9 @@ that the primary resource acted on or with another resource:
]
```

## Events in the Cloud UI
## Events in the UI

Prefect Cloud provides an interactive dashboard to analyze and take action on events that occurred in your workspace on
the event feed page.
The Prefect UI provides an interactive dashboard to analyze and take action on events that occurred in your workspace on the event feed page.

![Event feed](/3.0rc/img/ui/event-feed.png)

Expand All @@ -129,10 +129,10 @@ resource, related resources, and its payload.

## Respond to events

From an event page, you can configure an [automation](/3.0rc/automate/events/automations-triggers) to trigger on
From an event page, you can configure an [automation](/3.0rc/automate/events/automations-triggers/) to trigger on
the observation of matching events—or a lack of matching events—by clicking the automate button in the overflow menu:

![Automation from event](/3.0rc/img/ui/automation-from-event.png)

The default trigger configuration fires every time it sees an event with a matching resource identifier. Advanced
configuration is possible through [custom triggers](/3.0rc/automate/events/automations-triggers/).
The default trigger configuration fires every time it sees an event with a matching resource identifier.
Advanced configuration is possible through [custom triggers](/3.0rc/automate/events/custom-triggers/).
1 change: 0 additions & 1 deletion docs/3.0rc/automate/incidents.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ description: Incidents in Prefect Cloud help identify, resolve, and document iss

Incidents help you manage inevitable workflow disruptions, minimize their impact, and ensure operational continuity. With incidents, you can identify, resolve, and document issues with workflows, facilitating collaboration and compliance.


Incidents vary in nature and severity, ranging from minor glitches to critical system failures. With [automations](#incident-automations), activity in a workspace can be paused when an incident is created and resumed when the incident is resolved.

Incorporating incidents into your Prefect workflow facilitates:
Expand Down
1 change: 1 addition & 0 deletions docs/mint.json
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@
"group": "Automate",
"version": "3.0rc",
"pages": [
"3.0rc/automate/automate-overview",
"3.0rc/automate/add-schedules",
"3.0rc/automate/events/events",
"3.0rc/automate/events/automations-triggers",
Expand Down

0 comments on commit d3ff0ec

Please sign in to comment.