Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

SkipIfAlreadyDone -> SkipIfAlreadyTerminated

天舟5e655d0bd5a6
diff --git a/api/task_check_run.go b/api/task_check_run.go
index b6d564bce7..e69dc69897 100644
--- a/api/task_check_run.go
+++ b/api/task_check_run.go
@@ -117,7 +117,7 @@ type TaskCheckRunCreate struct {
// for this (TaskId, Type) pair. The check is done at the store layer so that we can wrap it in the
// same transaction.
// This is NOT persisted into the db
- SkipIfAlreadyDone bool
+ SkipIfAlreadyTerminated bool
}
type TaskCheckRunFind struct {
@@ -155,8 +155,8 @@ type TaskCheckRunStatusPatch struct {
type TaskCheckRunService interface {
// For a particular task and a particular check type, we only create a new TaskCheckRun if matches all conditions below:
// 1. There is no existing RUNNING check run. If this is the case, then returns that RUNNING check run.
- // 2. If SkipIfAlreadyDone is false, or if SkipIfAlreadyDone is true and there is no DONE check run. If this is the case,
- // then returns that DONE check run.
+ // 2. If SkipIfAlreadyTerminated is false, or if SkipIfAlreadyTerminated is true and there is no DONE/FAILED/CANCELED check run. If this is the case,
+ // then returns that terminated check run.
CreateTaskCheckRunIfNeeded(ctx context.Context, create *TaskCheckRunCreate) (*TaskCheckRun, error)
CreateTaskCheckRunTx(ctx context.Context, tx *sql.Tx, create *TaskCheckRunCreate) (*TaskCheckRun, error)
FindTaskCheckRunList(ctx context.Context, find *TaskCheckRunFind) ([]*TaskCheckRun, error)
diff --git a/server/pipeline.go b/server/pipeline.go
index b3e4fe63da..3f6169f58c 100644
--- a/server/pipeline.go
+++ b/server/pipeline.go
@@ -53,13 +53,13 @@ func (s *Server) ScheduleNextTaskIfNeeded(ctx context.Context, pipeline *api.Pip
return nil, nil
}
- skipIfAlreadyDone := true
+ skipIfAlreadyTerminated := true
if task.Status == api.TaskPendingApproval {
- return s.TaskCheckScheduler.ScheduleCheckIfNeeded(ctx, task, api.SYSTEM_BOT_ID, skipIfAlreadyDone)
+ return s.TaskCheckScheduler.ScheduleCheckIfNeeded(ctx, task, api.SYSTEM_BOT_ID, skipIfAlreadyTerminated)
}
if task.Status == api.TaskPending {
- if _, err := s.TaskCheckScheduler.ScheduleCheckIfNeeded(ctx, task, api.SYSTEM_BOT_ID, skipIfAlreadyDone); err != nil {
+ if _, err := s.TaskCheckScheduler.ScheduleCheckIfNeeded(ctx, task, api.SYSTEM_BOT_ID, skipIfAlreadyTerminated); err != nil {
return nil, err
}
updatedTask, err := s.TaskScheduler.Schedule(context.Background(), task)
diff --git a/server/task.go b/server/task.go
index 0758006217..8bc33b1055 100644
--- a/server/task.go
+++ b/server/task.go
@@ -96,11 +96,11 @@ func (s *Server) registerTaskRoutes(g *echo.Group) {
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Errorf("failed to marshal statement advise payload: %v, err: %w", task.Name, err))
}
_, err = s.TaskCheckRunService.CreateTaskCheckRunIfNeeded(context.Background(), &api.TaskCheckRunCreate{
- CreatorId: api.SYSTEM_BOT_ID,
- TaskId: task.ID,
- Type: api.TaskCheckDatabaseStatementSyntax,
- Payload: string(payload),
- SkipIfAlreadyDone: false,
+ CreatorId: api.SYSTEM_BOT_ID,
+ TaskId: task.ID,
+ Type: api.TaskCheckDatabaseStatementSyntax,
+ Payload: string(payload),
+ SkipIfAlreadyTerminated: false,
})
if err != nil {
// It's OK if we failed to trigger a check, just emit an error log
@@ -180,8 +180,8 @@ func (s *Server) registerTaskRoutes(g *echo.Group) {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to update task status").SetInternal(err)
}
- skipIfAlreadyDone := false
- updatedTask, err := s.TaskCheckScheduler.ScheduleCheckIfNeeded(context.Background(), task, c.Get(GetPrincipalIdContextKey()).(int), skipIfAlreadyDone)
+ skipIfAlreadyTerminated := false
+ updatedTask, err := s.TaskCheckScheduler.ScheduleCheckIfNeeded(context.Background(), task, c.Get(GetPrincipalIdContextKey()).(int), skipIfAlreadyTerminated)
if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to run task check \"%v\"", task.Name)).SetInternal(err)
@@ -386,8 +386,8 @@ func (s *Server) ChangeTaskStatusWithPatch(ctx context.Context, task *api.Task,
// Schedule the task if it's being just approved
if task.Status == api.TaskPendingApproval && updatedTask.Status == api.TaskPending {
- skipIfAlreadyDone := false
- if _, err := s.TaskCheckScheduler.ScheduleCheckIfNeeded(ctx, updatedTask, api.SYSTEM_BOT_ID, skipIfAlreadyDone); err != nil {
+ skipIfAlreadyTerminated := false
+ if _, err := s.TaskCheckScheduler.ScheduleCheckIfNeeded(ctx, updatedTask, api.SYSTEM_BOT_ID, skipIfAlreadyTerminated); err != nil {
return nil, fmt.Errorf("failed to schedule task check \"%v\" after approval", updatedTask.Name)
}
diff --git a/server/task_check_scheduler.go b/server/task_check_scheduler.go
index d7ed7264c5..b8330f927c 100644
--- a/server/task_check_scheduler.go
+++ b/server/task_check_scheduler.go
@@ -151,7 +151,7 @@ func (s *TaskCheckScheduler) Register(taskType string, executor TaskCheckExecuto
s.executors[taskType] = executor
}
-func (s *TaskCheckScheduler) ScheduleCheckIfNeeded(ctx context.Context, task *api.Task, creatorId int, skipIfAlreadyDone bool) (*api.Task, error) {
+func (s *TaskCheckScheduler) ScheduleCheckIfNeeded(ctx context.Context, task *api.Task, creatorId int, skipIfAlreadyTerminated bool) (*api.Task, error) {
if task.Type == api.TaskDatabaseSchemaUpdate {
taskPayload := &api.TaskDatabaseSchemaUpdatePayload{}
if err := json.Unmarshal([]byte(task.Payload), taskPayload); err != nil {
@@ -176,22 +176,22 @@ func (s *TaskCheckScheduler) ScheduleCheckIfNeeded(ctx context.Context, task *ap
return nil, fmt.Errorf("failed to marshal statement advise payload: %v, err: %w", task.Name, err)
}
_, err = s.server.TaskCheckRunService.CreateTaskCheckRunIfNeeded(ctx, &api.TaskCheckRunCreate{
- CreatorId: creatorId,
- TaskId: task.ID,
- Type: api.TaskCheckDatabaseStatementFakeAdvise,
- Payload: string(payload),
- SkipIfAlreadyDone: skipIfAlreadyDone,
+ CreatorId: creatorId,
+ TaskId: task.ID,
+ Type: api.TaskCheckDatabaseStatementFakeAdvise,
+ Payload: string(payload),
+ SkipIfAlreadyTerminated: skipIfAlreadyTerminated,
})
if err != nil {
return nil, err
}
_, err = s.server.TaskCheckRunService.CreateTaskCheckRunIfNeeded(ctx, &api.TaskCheckRunCreate{
- CreatorId: creatorId,
- TaskId: task.ID,
- Type: api.TaskCheckDatabaseStatementSyntax,
- Payload: string(payload),
- SkipIfAlreadyDone: skipIfAlreadyDone,
+ CreatorId: creatorId,
+ TaskId: task.ID,
+ Type: api.TaskCheckDatabaseStatementSyntax,
+ Payload: string(payload),
+ SkipIfAlreadyTerminated: skipIfAlreadyTerminated,
})
if err != nil {
return nil, err
diff --git a/store/task_check_run.go b/store/task_check_run.go
index 6857990fd2..b6bd055455 100644
--- a/store/task_check_run.go
+++ b/store/task_check_run.go
@@ -35,8 +35,10 @@ func (s *TaskCheckRunService) CreateTaskCheckRunIfNeeded(ctx context.Context, cr
defer tx.Rollback()
statusList := []api.TaskCheckRunStatus{api.TaskCheckRunRunning}
- if create.SkipIfAlreadyDone {
+ if create.SkipIfAlreadyTerminated {
statusList = append(statusList, api.TaskCheckRunDone)
+ statusList = append(statusList, api.TaskCheckRunFailed)
+ statusList = append(statusList, api.TaskCheckRunCanceled)
}
taskCheckRunFind := &api.TaskCheckRunFind{
TaskId: &create.TaskId,
@@ -50,9 +52,11 @@ func (s *TaskCheckRunService) CreateTaskCheckRunIfNeeded(ctx context.Context, cr
}
runningCount := 0
- if create.SkipIfAlreadyDone {
+ if create.SkipIfAlreadyTerminated {
for _, taskCheckRun := range taskCheckRunList {
- if taskCheckRun.Status == api.TaskCheckRunDone {
+ if taskCheckRun.Status == api.TaskCheckRunDone ||
+ taskCheckRun.Status == api.TaskCheckRunFailed ||
+ taskCheckRun.Status == api.TaskCheckRunCanceled {
return taskCheckRun, nil
} else if taskCheckRun.Status == api.TaskCheckRunRunning {
runningCount++