Skip to content

Commit 0e52847

Browse files
authored
Merge pull request #15 from taskbadger/sk/deprecate-task-actions
Deprecate per-task actions in docs
2 parents 3afd660 + f4e22fc commit 0e52847

10 files changed

Lines changed: 134 additions & 192 deletions

File tree

docs/actions.md

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
---
2+
title: Actions
3+
---
4+
# Actions
5+
6+
Actions are at the core of Task Badger's alerting. They let you send notifications and
7+
callouts based on task events — status changes, progress thresholds, or exceeding an
8+
expected runtime.
9+
10+
Actions are configured in the Task Badger web UI and apply across your tasks, so you no
11+
longer need to attach alerting to individual tasks in your code.
12+
13+
!!!note "Deprecation"
14+
Attaching actions to individual tasks via the SDK, CLI, or API is **deprecated** and
15+
will be removed in a future release. Configure actions in the web UI instead — see
16+
[Migrating from per-task actions](#migrating-from-per-task-actions).
17+
18+
## How actions work
19+
20+
An action combines two things:
21+
22+
- A **channel** — the reusable destination that delivers the notification (email, web hook).
23+
Channels are configured once under **Integrations** and can be reused by many actions.
24+
- A **trigger** — the task event(s) that cause the action to fire.
25+
26+
When a task reaches a trigger point, Task Badger runs the action's channel with the current
27+
task details.
28+
29+
## Channels
30+
31+
A channel is a reusable destination for notifications. See [Integrations](integrations.md)
32+
for the available channel types and how to configure them.
33+
34+
## Creating an action
35+
36+
Actions are created in the web UI under **Integrations → Global Actions**.
37+
38+
Each action has the following settings:
39+
40+
| Setting | Description |
41+
|----------------|--------------------------------------------------------------------------------------|
42+
| Name | A label to identify the action. |
43+
| Project filter | Limit the action to a single project. Leave blank to apply to tasks in all projects. |
44+
| Name filter | A regular expression matched against the task name. Leave blank to match all tasks. |
45+
| Channel | The [integration](integrations.md) used to deliver the notification. |
46+
| Trigger | The task event(s) that fire the action — see [Triggers](#triggers). |
47+
48+
Actions can be enabled or disabled at any time without deleting them.
49+
50+
## Triggers
51+
52+
A trigger is a comma-separated list of trigger points. Each trigger point is one of the following:
53+
54+
* A numeric value which is matched against the task `value`.
55+
* A percentage value which is matched against the task `value_percent`.
56+
* A task status which is matched against the task `status`.
57+
* A special value `max_runtime_exceeded` which is matched when the task exceeds its `max_runtime` value.
58+
59+
Numeric and percentage trigger points can also be prefixed with `*/` to indicate that the trigger should
60+
fire at regular intervals. For example, `*/50%` will fire at 0%, 50% and 100%.
61+
62+
Examples:
63+
64+
| Trigger | Trigger Fire Points |
65+
|-----------------------|------------------------------------------------------------------------------|
66+
| `*/30%` | When `value_percent` passes any multiple of 30%: 0%, 30%, 60%, 90% |
67+
| `success,error,stale` | When the state changes to any of the listed states |
68+
| `95%,250,error` | At 95%, when the value reaches or passes 250, when the state becomes `error` |
69+
70+
### Trigger edge cases
71+
72+
If a task value or status skips past multiple trigger points, only the last matching trigger will be
73+
executed.
74+
75+
For example, an action configured with `20,40,80` whose value goes from `0` directly to `90` will
76+
skip over the `20` and `40` events and only fire the `80` event. This also applies to task
77+
status triggers.
78+
79+
This also applies to multiple trigger points that are reached simultaneously, for example, let's say
80+
an action has the following trigger: `100,success`. It is quite likely that the task could reach
81+
both those states at the same time but the action will only fire once.
82+
83+
## Migrating from per-task actions
84+
85+
Previously, actions were attached to individual tasks when they were created — via the
86+
`actions` argument in the SDK, the `--action` option in the CLI, or the task `actions` field
87+
in the API. This approach is **deprecated**: existing per-task actions keep working for now,
88+
but the ability to create them will be removed in a future release.
89+
90+
To migrate, recreate your alerting as global actions in the web UI:
91+
92+
1. Configure the channels you need under **Integrations** (see [Integrations](integrations.md)).
93+
2. Under **Integrations → Global Actions**, create an action for each alert you want, using a
94+
name filter and/or project filter to target the same tasks you previously attached actions to.
95+
96+
Global actions replace per-task actions entirely — a single action with a name filter can cover
97+
every task that used to carry an inline action definition.

docs/api.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ task URL is:
2020
| Update task action | `PATCH /api/{org}/{project}/tasks/{task_id}/actions/{action_id}/` |
2121
| Cancel task action | `DELETE /api/{org}/{project}/tasks/{task_id}/actions/{action_id}/` |
2222

23+
!!!note "Deprecation"
24+
The endpoints for adding and updating task actions (as well as the `actions` field on the
25+
create/update task endpoints) are **deprecated** and will be removed in a future release.
26+
Configure [actions](actions.md) in the web UI instead.
2327

2428
Full details of the API endpoints can be viewed at [https://taskbadger.net/api/docs/](https://taskbadger.net/api/docs/){:target="_blank"}
2529

docs/cli.md

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -62,25 +62,10 @@ For more details on these commands run `taskbadger <command> --help`.
6262

6363
## Actions
6464

65-
You can create actions for CLI tasks using the `--action` (`-a`) argument. The
66-
format for this argument is string with three components, separated by a space:
67-
68-
```mermaid
69-
flowchart LR
70-
trigger --- integration
71-
integration --- config
72-
```
73-
74-
The config parameter is a comma-separated list of key value pairs.
75-
76-
Here is an example:
77-
78-
```bash
79-
$ taskbadger run "demo task" --action error email to:me@test.com -- path/to/script.sh
80-
```
81-
82-
If the task state becomes `stale` or `error`, use the `email` integration to
83-
send a notification to `me@test.com`.
65+
!!!note "Deprecation"
66+
The `--action` (`-a`) argument for attaching actions to CLI tasks is **deprecated** and
67+
will be removed in a future release. Configure [actions](actions.md) in the web UI instead.
68+
Actions apply across your tasks, so you no longer need to attach them per command.
8469

8570
## Configuration
8671

docs/data_model.md

Lines changed: 5 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ The main attributes or a task are:
5151

5252
`max_runtime`
5353

54-
: This value can be used in conjunction with task actions and monitors to trigger actions if a task
54+
: This value can be used in conjunction with [actions](actions.md) and monitors to trigger alerts if a task
5555
exceeds its expected runtime. The value is in seconds.
5656

5757
`stale_timeout`
@@ -201,64 +201,10 @@ modified again (with the potential exception of 'stale').
201201
to any other state via an update.
202202

203203

204-
## Task Actions
204+
## Actions
205205

206-
Actions are at the core of Task Badger's secret sauce. They allow you to send notifications, perform callouts,
206+
Actions are at the core of Task Badger's alerting. They allow you to send notifications, perform callouts,
207207
and more based on task events.
208208

209-
Every action specifies an [integration](integrations.md) e.g. `email`, and a trigger definition which is
210-
like a crontab expression, but for tasks. For example, `*/25%,success` means, "execute
211-
this action when the task value passes 25%, 50%, 75%, 100% and when the task status
212-
is set to `success`".
213-
214-
A task may have multiple actions, each with their own integration and trigger definition.
215-
216-
Here is an example of an action:
217-
218-
```json
219-
{
220-
"id": 640,
221-
"task": "57ae8eVBrH7jbDgmYj6Ut2vR9S",
222-
"trigger": "success,error",
223-
"integration": "email",
224-
"status": "active",
225-
"config": {
226-
"to": "me@example.com,you@example.com"
227-
},
228-
"created": "2022-11-16T07:10:30.551808Z",
229-
"updated": "2022-11-16T07:10:30.551818Z"
230-
}
231-
```
232-
233-
### Action Triggers
234-
235-
An action trigger is a comma-separated list of trigger points. Each trigger point is one of the following:
236-
237-
* A numeric value which is matched against the task `value`.
238-
* A percentage value which is matched against the task `value_percent`.
239-
* A task status which is matched against the task `status`.
240-
* A special value `max_runtime_exeeded` which is matched when the task exceeds its `max_runtime` value.
241-
242-
Numeric and percentage trigger points can also be prefixed with `*/` to indicate that the trigger should
243-
fire at regular intervals. For example, `*/50%` will fire at 0%, 50% and 100%.
244-
245-
Examples:
246-
247-
| Trigger | Trigger Fire Points |
248-
|-----------------------|------------------------------------------------------------------------------|
249-
| `*/30%` | When `value_percent` passes any multiple of 30%: 0%, 30%, 60%, 90% |
250-
| `success,error,stale` | When the state changes to any of the listed states |
251-
| `95%,250,error` | At 95%, when the value reaches or passes 250, when the state becomes `error` |
252-
253-
### Action Edge cases
254-
255-
If a task value or status skips past multiple trigger points, only the last matching trigger will be
256-
executed.
257-
258-
For example, an action configured with `20,40,80` whose value goes from `0` directly to `90` will
259-
skip over the `20` and `40` events and only fire the `80` event. This also applies to task
260-
status triggers.
261-
262-
This also applies to multiple trigger points that are reached simultaneously, for example, let's say
263-
an action has the following trigger: `100,success`. It is quite likely that the task could reach
264-
both those states at the same time but the action will only fire once.
209+
Actions are configured in the web UI and apply across your tasks. See [Actions](actions.md) for
210+
details on channels and triggers.

docs/index.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,14 @@ taskbadger run "my task" -- ./script.sh
4949

5050
- **Task tracking** — monitor status, progress, and metadata for any background job
5151
- **Celery integration** — automatic tracking of all Celery tasks with zero code changes
52-
- **Actions and triggers** — get notified via email, webhook, or other integrations on task events
52+
- **Actions and triggers** — get notified via email, webhook, or other integrations on task events, configured in the web UI
5353
- **CLI** — monitor shell commands without writing code
5454

5555
## Learn More
5656

5757
- [Quick Start](quick.md) — full setup walkthrough
5858
- [Python SDK](python.md) — SDK reference
5959
- [CLI](cli.md) — command line usage
60-
- [Data Model](data_model.md) — task states, actions, and triggers
60+
- [Data Model](data_model.md) — task states and fields
61+
- [Actions](actions.md) — notifications and triggers
6162
- [API Endpoints](api.md) — REST API reference

docs/integrations.md

Lines changed: 9 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ title: Integrations
44

55
# Integrations
66

7-
Task Badger integrations are what power the actions. When an action is triggered it causes
8-
the specified integration to execute.
7+
Integrations are the channels that power [actions](actions.md). When an action is triggered
8+
it delivers a notification through the specified integration.
99

10-
Each action specifies the integration ID as well as a set of configuration used by the integration.
10+
Integrations are configured once in the web UI under **Integrations** and can be reused by
11+
many actions. Each integration has an ID which is used to reference it from an action.
1112

1213
## Email
1314

@@ -21,76 +22,17 @@ Email a set of recipients with the current status of the task.
2122
|-----------|-----------------------------------------------------------|
2223
| `to` | Comma-separated list of recipient email addresses. Max 5. |
2324

24-
**Example Usage**
25-
26-
=== "Python"
27-
28-
```python
29-
action = Action(
30-
"success,error",
31-
integration=EmailIntegration(to="me@example.com")
32-
)
33-
task = Task.create(name="task name", actions=[action])
34-
```
35-
36-
=== "Cli"
37-
38-
```shell
39-
taskbadger run "demo task" --action error,sucess email to:me@test.com -- path/to/script.sh
40-
```
41-
42-
=== "Shell"
43-
44-
```shell
45-
$ curl -X PATCH "https://taskbadger.net/api/${ORG}/${PROJECT}/tasks/" \
46-
-H "Authorization: Bearer ${API_KEY}" \
47-
-H "Content-Type: application/json" \
48-
-d '{"name":"demo", "actions":[{"integration":"email","trigger":"success,error","config":{"to":"me@example.com"}}]}'
49-
```
50-
5125
## Web Hook
5226

5327
The web hook integration allows you to call a URL with a task payload.
5428

55-
For security reasons web hooks must first be created on the web UI before they can be used
56-
in task actions. This can be done by going to **Integrations** in the sidebar navigation.
57-
58-
Each web hook will have its own unique ID which is what will be used when creating actions.
29+
Web hooks must first be created in the web UI, under **Integrations** in the sidebar
30+
navigation, before they can be used by an action.
5931

6032
**Integration ID**: `webhook:<slug>`
6133

6234
**Configuration**
6335

64-
There is currently no additional configuration required for Web Hooks other than
65-
the configuration provided when creating them on the web.
66-
67-
68-
69-
**Example Usage**
70-
71-
=== "Python"
72-
73-
```python
74-
action = Action(
75-
"success,error",
76-
integration=WebhookIntegration(id="webhook:demo-123")
77-
)
78-
task = Task.create(name="task name", actions=[action])
79-
```
80-
81-
=== "Cli"
82-
83-
Since no additional configuration is required we must pass an empty string:
84-
85-
```shell
86-
taskbadger run "demo task" --action error,sucess webhook:demo-123 "" -- path/to/script.sh
87-
```
88-
89-
=== "Shell"
90-
91-
```shell
92-
$ curl -X PATCH "https://taskbadger.net/api/${ORG}/${PROJECT}/tasks/" \
93-
-H "Authorization: Bearer ${API_KEY}" \
94-
-H "Content-Type: application/json" \
95-
-d '{"name":"demo", actions":[{"integration":"webhook:demo-test","trigger":"success,error","config":{}}]}'
96-
```
36+
There is currently no additional configuration required for web hooks other than
37+
the configuration provided when creating them in the web UI. Each web hook has its own
38+
unique ID (`webhook:<slug>`) which is used when referencing it from an action.

docs/python.md

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,20 +49,14 @@ The SDK provides a [Task](#taskbadger.Task) class which offers a convenient inte
4949
Tasks are created by calling the `Task.create` method:
5050

5151
```python
52-
from taskbadger import Task, Action, EmailIntegration
52+
from taskbadger import Task
5353

54-
# create a new task with custom data and an action definition
54+
# create a new task with custom data and tags
5555
task = Task.create(
5656
"task name",
5757
data={
5858
"custom": "data"
5959
},
60-
actions=[
61-
Action(
62-
trigger="*/10%,success,error",
63-
integration=EmailIntegration(to="me@example.com")
64-
)
65-
],
6660
tags={"tenant": "acme"}
6761
)
6862
```
@@ -75,8 +69,7 @@ from taskbadger import Task
7569
task = Task.get(task_id)
7670
```
7771

78-
The task object provides methods for updating the properties of a task, adding custom data
79-
and adding actions.
72+
The task object provides methods for updating the properties of a task and adding custom data.
8073

8174
### Connection management
8275

0 commit comments

Comments
 (0)