Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
Add error column to task_run to store error info when run failed
天舟f17093767bc3
diff --git a/backend/api/task_run.go b/backend/api/task_run.goindex 32673d5d5f..6ecc4aa566 100644--- a/backend/api/task_run.go+++ b/backend/api/task_run.go@@ -48,6 +48,7 @@ type TaskRun struct {Name string `jsonapi:"attr,name"`Status TaskRunStatus `jsonapi:"attr,status"`Type TaskType `jsonapi:"attr,type"`+ Error string `jsonapi:"attr,error"`Payload []byte `jsonapi:"attr,payload"`}@@ -91,6 +92,8 @@ type TaskRunStatusPatch struct {// Domain specific fieldsStatus TaskRunStatus+ // If status is FAILED, then we will set the error+ Error *string}type TaskRunService interface {diff --git a/backend/server/task_executor_sql.go b/backend/server/task_executor_sql.goindex 785c5eea7c..b29d3bb159 100644--- a/backend/server/task_executor_sql.go+++ b/backend/server/task_executor_sql.go@@ -23,11 +23,11 @@ type SqlTaskExecutor struct {func (exec *SqlTaskExecutor) RunOnce(ctx context.Context, server *Server, task *api.Task) (terminated bool, err error) {payload := &api.TaskDatabaseSchemaUpdatePayload{}if err := json.Unmarshal(task.Payload, payload); err != nil {- return true, fmt.Errorf("sql executor: invalid payload: %w", err)+ return true, fmt.Errorf("invalid schema update payload: %w", err)}if payload.Sql == "" {- return true, fmt.Errorf("sql executor: missing sql statement")+ return true, fmt.Errorf("missing sql statement")}exec.l.Info(fmt.Sprintf("sql executor: run %v", payload.Sql))diff --git a/backend/server/task_scheduler.go b/backend/server/task_scheduler.goindex d2d4e6f63b..eb388bcc17 100644--- a/backend/server/task_scheduler.go+++ b/backend/server/task_scheduler.go@@ -63,7 +63,13 @@ func (s *TaskScheduler) Run() error {if done {if err != nil {s.l.Info(fmt.Sprintf("Task failed '%v(%v)': %v.\n", task.Name, task.ID, err))- s.server.ChangeTaskStatus(context.Background(), task, api.TaskFailed, api.SYSTEM_BOT_ID)+ taskStatusPatch := &api.TaskStatusPatch{+ ID: task.ID,+ UpdaterId: api.SYSTEM_BOT_ID,+ Status: api.TaskFailed,+ Comment: err.Error(),+ }+ s.server.ChangeTaskStatusWithPatch(context.Background(), task, taskStatusPatch)continue}diff --git a/backend/store/migration/0001_init_schema.up.sql b/backend/store/migration/0001_init_schema.up.sqlindex 58b10ecc57..b2f6f8bcd7 100644--- a/backend/store/migration/0001_init_schema.up.sql+++ b/backend/store/migration/0001_init_schema.up.sql@@ -497,6 +497,7 @@ CREATE TABLE task_run ()),`type` TEXT NOT NULL CHECK (`type` LIKE 'bb.task.%'),+ error TEXT NOT NULL DEFAULT '',payload TEXT NOT NULL DEFAULT '{}');diff --git a/backend/store/seed/0120_task_run.sql b/backend/store/seed/0120_task_run.sqlindex 2724e61084..6aa223af4b 100644--- a/backend/store/seed/0120_task_run.sql+++ b/backend/store/seed/0120_task_run.sql@@ -7,7 +7,8 @@ INSERT INTOtask_id,name,`status`,- `type`+ `type`,+ error)VALUES(@@ -17,5 +18,6 @@ VALUES11006,'UPDATE fakedb1 task run','FAILED',- 'bb.task.database.schema.update'+ 'bb.task.database.schema.update',+ 'fake execution error');\ No newline at end of filediff --git a/backend/store/task.go b/backend/store/task.goindex fc686504ac..c65caa44ce 100644--- a/backend/store/task.go+++ b/backend/store/task.go@@ -296,6 +296,7 @@ func (s *TaskService) patchTaskStatus(ctx context.Context, tx *Tx, patch *api.TataskRunStatusPatch.Status = api.TaskRunDonecase api.TaskFailed:taskRunStatusPatch.Status = api.TaskRunFailed+ taskRunStatusPatch.Error = &patch.Commentcase api.TaskPending:case api.TaskPendingApproval:case api.TaskCanceled:diff --git a/backend/store/task_run.go b/backend/store/task_run.goindex 615eda6416..dcacd70783 100644--- a/backend/store/task_run.go+++ b/backend/store/task_run.go@@ -39,7 +39,7 @@ func (s *TaskRunService) CreateTaskRun(ctx context.Context, tx *sql.Tx, create *payload)VALUES (?, ?, ?, ?, 'RUNNING', ?, ?)- RETURNING id, creator_id, created_ts, updater_id, updated_ts, task_id, name, `+"`status`, `type`, payload"+`+ RETURNING id, creator_id, created_ts, updater_id, updated_ts, task_id, name, `+"`status`, `type`, error, payload"+``,create.CreatorId,create.CreatorId,@@ -66,6 +66,7 @@ func (s *TaskRunService) CreateTaskRun(ctx context.Context, tx *sql.Tx, create *&taskRun.Name,&taskRun.Status,&taskRun.Type,+ &taskRun.Error,&taskRun.Payload,); err != nil {return nil, FormatError(err)@@ -104,6 +105,9 @@ func (s *TaskRunService) PatchTaskRunStatus(ctx context.Context, tx *sql.Tx, pat// Build UPDATE clause.set, args := []string{}, []interface{}{}set, args = append(set, "`status` = ?"), append(args, patch.Status)+ if v := patch.Error; v != nil {+ set, args = append(set, "error = ?"), append(args, *v)+ }// Build WHERE clause.where := []string{"1 = 1"}@@ -118,7 +122,7 @@ func (s *TaskRunService) PatchTaskRunStatus(ctx context.Context, tx *sql.Tx, patUPDATE task_runSET `+strings.Join(set, ", ")+`WHERE `+strings.Join(where, " AND ")+`- RETURNING id, creator_id, created_ts, updater_id, updated_ts, task_id, name, `+"`status`, `type`, payload"+`+ RETURNING id, creator_id, created_ts, updater_id, updated_ts, task_id, name, `+"`status`, `type`, error, payload"+``,args...,)@@ -140,6 +144,7 @@ func (s *TaskRunService) PatchTaskRunStatus(ctx context.Context, tx *sql.Tx, pat&taskRun.Name,&taskRun.Status,&taskRun.Type,+ &taskRun.Error,&taskRun.Payload,); err != nil {return nil, FormatError(err)@@ -177,6 +182,7 @@ func (s *TaskRunService) findTaskRunList(ctx context.Context, tx *sql.Tx, find *name,`+"`status`,"+``+"`type`,"+`+ error,payloadFROM task_runWHERE `+strings.Join(where, " AND "),@@ -201,6 +207,7 @@ func (s *TaskRunService) findTaskRunList(ctx context.Context, tx *sql.Tx, find *&taskRun.Name,&taskRun.Status,&taskRun.Type,+ &taskRun.Error,&taskRun.Payload,); err != nil {return nil, FormatError(err)diff --git a/frontend/src/components/TaskRunTable.vue b/frontend/src/components/TaskRunTable.vueindex d1e0ec46c5..c6b0a5cd93 100644--- a/frontend/src/components/TaskRunTable.vue+++ b/frontend/src/components/TaskRunTable.vue@@ -8,7 +8,7 @@:rowClickable="false"><template v-slot:body="{ rowData: taskRun }">- <BBTableCell :leftPadding="4" class="table-cell w-24">+ <BBTableCell :leftPadding="4" class="table-cell w-12"><div class="flex flex-row space-x-2"><divclass="@@ -73,7 +73,10 @@</div></div></BBTableCell>- <BBTableCell class="table-cell w-16">+ <BBTableCell class="table-cell w-36">+ {{ taskRun.error }}+ </BBTableCell>+ <BBTableCell class="table-cell w-12"><div class="flex flex-row items-center space-x-2"><BBAvatar :username="taskRun.creator.name" :size="'small'" /><div class="flex flex-col">@@ -85,10 +88,10 @@</div></div></BBTableCell>- <BBTableCell class="table-cell w-16">+ <BBTableCell class="table-cell w-12">{{ humanizeTs(taskRun.createdTs) }}</BBTableCell>- <BBTableCell class="table-cell w-16">+ <BBTableCell class="table-cell w-12">{{ humanizeTs(taskRun.updatedTs) }}</BBTableCell></template>@@ -104,6 +107,9 @@ const columnList: BBTableColumn[] = [{title: "Status",},+ {+ title: "Error",+ },{title: "Invoker",},diff --git a/frontend/src/types/pipeline.ts b/frontend/src/types/pipeline.tsindex a560dafd2a..76a887c06f 100644--- a/frontend/src/types/pipeline.ts+++ b/frontend/src/types/pipeline.ts@@ -258,5 +258,6 @@ export type TaskRun = {name: string;status: TaskRunStatus;type: TaskType;+ error: string;payload?: TaskPayload;};