Skip to content

Commit 83b0e81

Browse files
committed
feat: incorporate scope into tasks
Adds a "scope" concept to tasks to support tasks that apply to non- database entities. With this change, the task's parent is identified by the `scope` and `entity_id` fields. This changes the way that tasks and task logs are stored, so we'll add a migration to move existing tasks in a subsequent commit. PLAT-347
1 parent 278a4cb commit 83b0e81

40 files changed

+1559
-201
lines changed

api/apiv1/design/task.go

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ var Task = g.Type("Task", func() {
1010
g.Description("The parent task ID of the task.")
1111
g.Example("439eb515-e700-4740-b508-4a3f12ec4f83")
1212
})
13+
g.Attribute("scope", g.String, func() {
14+
g.Description("The scope of the task (database or host).")
15+
g.Example("database")
16+
})
17+
g.Attribute("entity_id", g.String, func() {
18+
g.Description("The entity ID (database_id or host_id) that this task belongs to.")
19+
g.Example("02f1a7db-fca8-4521-b57a-2a375c1ced51")
20+
})
1321
g.Attribute("database_id", g.String, func() {
1422
g.Description("The database ID of the task.")
1523
g.Example("02f1a7db-fca8-4521-b57a-2a375c1ced51")
@@ -55,9 +63,11 @@ var Task = g.Type("Task", func() {
5563
g.Example("failed to connect to database")
5664
})
5765

58-
g.Required("database_id", "task_id", "created_at", "type", "status")
66+
g.Required("scope", "entity_id", "task_id", "created_at", "type", "status")
5967

6068
g.Example(map[string]any{
69+
"scope": "database",
70+
"entity_id": "storefront",
6171
"completed_at": "2025-06-18T16:52:35Z",
6272
"created_at": "2025-06-18T16:52:05Z",
6373
"database_id": "storefront",
@@ -88,10 +98,22 @@ var TaskLogEntry = g.Type("TaskLogEntry", func() {
8898
})
8999

90100
var TaskLog = g.Type("TaskLog", func() {
101+
g.Attribute("scope", g.String, func() {
102+
g.Description("The scope of the task (database or host).")
103+
g.Example("database")
104+
})
105+
g.Attribute("entity_id", g.String, func() {
106+
g.Description("The entity ID (database_id or host_id) that this task log belongs to.")
107+
g.Example("02f1a7db-fca8-4521-b57a-2a375c1ced51")
108+
})
91109
g.Attribute("database_id", g.String, func() {
92-
g.Description("The database ID of the task log.")
110+
g.Description("The database ID of the task log. Deprecated: use entity_id instead.")
93111
g.Example("02f1a7db-fca8-4521-b57a-2a375c1ced51")
94112
})
113+
g.Attribute("host_id", g.String, func() {
114+
g.Description("The host ID of the task log. Deprecated: use entity_id instead.")
115+
g.Example("host-1")
116+
})
95117
g.Attribute("task_id", g.String, func() {
96118
g.Description("The unique ID of the task log.")
97119
g.Example("3c875a27-f6a6-4c1c-ba5f-6972fb1fc348")
@@ -109,12 +131,13 @@ var TaskLog = g.Type("TaskLog", func() {
109131
g.Description("Entries in the task log.")
110132
})
111133

112-
g.Required("database_id", "task_id", "task_status", "entries")
134+
g.Required("scope", "entity_id", "task_id", "task_status", "entries")
113135

114136
g.Example("node_backup task log", func() {
115137
g.Description("The task log from a 'node_backup' task. These messages are produced by pgbackrest.")
116138
g.Value(map[string]any{
117-
"database_id": "storefront",
139+
"scope": "database",
140+
"entity_id": "storefront",
118141
"entries": []map[string]any{
119142
{
120143
"message": "P00 INFO: backup command begin 2.55.1: --config=/opt/pgedge/configs/pgbackrest.backup.conf --exec-id=198-b17fae6e --log-level-console=info --no-log-timestamp --pg1-path=/opt/pgedge/data/pgdata --pg1-user=pgedge --repo1-cipher-type=none --repo1-path=/backups/databases/storefront/n1 --repo1-retention-full=7 --repo1-retention-full-type=time --repo1-type=posix --stanza=db --start-fast --type=full",
@@ -178,7 +201,8 @@ var TaskLog = g.Type("TaskLog", func() {
178201
g.Example("update task log", func() {
179202
g.Description("This is the task log of an update task. This example excludes many entries for brevity.")
180203
g.Value(map[string]any{
181-
"database_id": "storefront",
204+
"scope": "database",
205+
"entity_id": "storefront",
182206
"entries": []map[string]any{
183207
{
184208
"message": "refreshing current state",
@@ -247,6 +271,8 @@ var ListDatabaseTasksResponse = g.Type("ListDatabaseTasksResponse", func() {
247271
{
248272
"completed_at": "2025-06-18T17:54:36Z",
249273
"created_at": "2025-06-18T17:54:28Z",
274+
"scope": "database",
275+
"entity_id": "storefront",
250276
"database_id": "storefront",
251277
"instance_id": "storefront-n1-689qacsi",
252278
"status": "completed",
@@ -256,6 +282,8 @@ var ListDatabaseTasksResponse = g.Type("ListDatabaseTasksResponse", func() {
256282
{
257283
"completed_at": "2025-06-18T17:54:04Z",
258284
"created_at": "2025-06-18T17:53:17Z",
285+
"scope": "database",
286+
"entity_id": "storefront",
259287
"database_id": "storefront",
260288
"status": "completed",
261289
"task_id": "0197842c-7c4f-7a8c-829e-7405c2a41c8c",
@@ -264,6 +292,8 @@ var ListDatabaseTasksResponse = g.Type("ListDatabaseTasksResponse", func() {
264292
{
265293
"completed_at": "2025-06-18T17:23:28Z",
266294
"created_at": "2025-06-18T17:23:14Z",
295+
"scope": "database",
296+
"entity_id": "storefront",
267297
"database_id": "storefront",
268298
"status": "completed",
269299
"task_id": "01978410-fb5d-7cd2-bbd2-66c0bf929dc0",
@@ -272,6 +302,8 @@ var ListDatabaseTasksResponse = g.Type("ListDatabaseTasksResponse", func() {
272302
{
273303
"completed_at": "2025-06-18T16:52:35Z",
274304
"created_at": "2025-06-18T16:52:05Z",
305+
"scope": "database",
306+
"entity_id": "storefront",
275307
"database_id": "storefront",
276308
"status": "completed",
277309
"task_id": "019783f4-75f4-71e7-85a3-c9b96b345d77",

api/apiv1/gen/control_plane/service.go

Lines changed: 13 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/apiv1/gen/control_plane/views/view.go

Lines changed: 9 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/apiv1/gen/http/control_plane/client/encode_decode.go

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/apiv1/gen/http/control_plane/client/types.go

Lines changed: 29 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/apiv1/gen/http/control_plane/server/encode_decode.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/apiv1/gen/http/control_plane/server/types.go

Lines changed: 30 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)