Skip to content

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

refactor: remove skipIfTerminated & timing task check executor (#2964)

p0ny9021733f1c46
diff --git a/api/task_check_run.go b/api/task_check_run.go
index a6a3cbeca6..0a439821cb 100644
--- a/api/task_check_run.go
+++ b/api/task_check_run.go
@@ -171,12 +171,6 @@ type TaskCheckRunCreate struct {
Type TaskCheckType `jsonapi:"attr,type"`
Comment string `jsonapi:"attr,comment"`
Payload string `jsonapi:"attr,payload"`
-
- // If true, then we will skip creating the task check run if there has already been a DONE check run
- // 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
- SkipIfAlreadyTerminated bool
}
// TaskCheckRunFind is the API message for finding task check runs.
diff --git a/server/pipeline.go b/server/pipeline.go
index 51b6a8ba91..2c99c9c822 100644
--- a/server/pipeline.go
+++ b/server/pipeline.go
@@ -50,7 +50,7 @@ func (s *Server) ScheduleActiveStage(ctx context.Context, pipeline *api.Pipeline
func (s *Server) schedulePipelineTaskCheck(ctx context.Context, pipeline *api.Pipeline) error {
for _, stage := range pipeline.StageList {
for _, task := range stage.TaskList {
- if _, err := s.TaskCheckScheduler.ScheduleCheckIfNeeded(ctx, task, api.SystemBotID, true /* skipIfAlreadyTerminated */); err != nil {
+ if _, err := s.TaskCheckScheduler.ScheduleCheckIfNeeded(ctx, task, api.SystemBotID); err != nil {
return errors.Wrapf(err, "failed to schedule task check for task %d", task.ID)
}
}
diff --git a/server/server.go b/server/server.go
index 7a59d04f77..3539fb2b42 100644
--- a/server/server.go
+++ b/server/server.go
@@ -266,9 +266,6 @@ func NewServer(ctx context.Context, prof Profile) (*Server, error) {
ghostSyncExecutor := NewTaskCheckGhostSyncExecutor()
taskCheckScheduler.Register(api.TaskCheckGhostSync, ghostSyncExecutor)
- timingExecutor := NewTaskCheckTimingExecutor()
- taskCheckScheduler.Register(api.TaskCheckGeneralEarliestAllowedTime, timingExecutor)
-
checkLGTMExecutor := NewTaskCheckLGTMExecutor()
taskCheckScheduler.Register(api.TaskCheckIssueLGTM, checkLGTMExecutor)
diff --git a/server/task.go b/server/task.go
index 8cfeedf955..142c338ce2 100644
--- a/server/task.go
+++ b/server/task.go
@@ -241,7 +241,7 @@ func (s *Server) registerTaskRoutes(g *echo.Group) {
return echo.NewHTTPError(http.StatusUnauthorized, fmt.Sprintf("Task not found with ID %d", taskID))
}
- taskUpdated, err := s.TaskCheckScheduler.ScheduleCheckIfNeeded(ctx, task, c.Get(getPrincipalIDContextKey()).(int), false /* skipIfAlreadyTerminated */)
+ taskUpdated, err := s.TaskCheckScheduler.ScheduleCheckIfNeeded(ctx, task, c.Get(getPrincipalIDContextKey()).(int))
if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to run task check \"%v\"", task.Name)).SetInternal(err)
}
@@ -393,10 +393,9 @@ func (s *Server) patchTask(ctx context.Context, task *api.Task, taskPatch *api.T
if taskPatched.Type == api.TaskDatabaseSchemaUpdateGhostSync {
_, err = s.store.CreateTaskCheckRunIfNeeded(ctx, &api.TaskCheckRunCreate{
- CreatorID: taskPatched.CreatorID,
- TaskID: task.ID,
- Type: api.TaskCheckGhostSync,
- SkipIfAlreadyTerminated: false,
+ CreatorID: taskPatched.CreatorID,
+ TaskID: task.ID,
+ Type: api.TaskCheckGhostSync,
})
if err != nil {
// It's OK if we failed to trigger a check, just emit an error log
@@ -419,11 +418,10 @@ func (s *Server) patchTask(ctx context.Context, task *api.Task, taskPatch *api.T
return nil, echo.NewHTTPError(http.StatusInternalServerError, errors.Wrapf(err, "failed to marshal statement advise payload: %v", task.Name))
}
_, err = s.store.CreateTaskCheckRunIfNeeded(ctx, &api.TaskCheckRunCreate{
- CreatorID: api.SystemBotID,
- TaskID: task.ID,
- Type: api.TaskCheckDatabaseStatementSyntax,
- Payload: string(payload),
- SkipIfAlreadyTerminated: false,
+ CreatorID: api.SystemBotID,
+ TaskID: task.ID,
+ Type: api.TaskCheckDatabaseStatementSyntax,
+ Payload: string(payload),
})
if err != nil {
// It's OK if we failed to trigger a check, just emit an error log
@@ -452,11 +450,10 @@ func (s *Server) patchTask(ctx context.Context, task *api.Task, taskPatch *api.T
return nil, echo.NewHTTPError(http.StatusInternalServerError, errors.Wrapf(err, "failed to marshal check statement type payload: %v", task.Name))
}
if _, err := s.store.CreateTaskCheckRunIfNeeded(ctx, &api.TaskCheckRunCreate{
- CreatorID: api.SystemBotID,
- TaskID: task.ID,
- Type: api.TaskCheckDatabaseStatementType,
- Payload: string(payload),
- SkipIfAlreadyTerminated: false,
+ CreatorID: api.SystemBotID,
+ TaskID: task.ID,
+ Type: api.TaskCheckDatabaseStatementType,
+ Payload: string(payload),
}); err != nil {
// It's OK if we failed to trigger a check, just emit an error log
log.Error("Failed to trigger statement type check after changing the task statement",
@@ -469,7 +466,9 @@ func (s *Server) patchTask(ctx context.Context, task *api.Task, taskPatch *api.T
}
}
- // create an activity and trigger task check for earliest allowed time update
+ // earliest allowed time update.
+ // - create an activity.
+ // - dismiss stale approval.
if taskPatched.EarliestAllowedTs != task.EarliestAllowedTs {
// create an activity
if issue == nil {
@@ -513,29 +512,6 @@ func (s *Server) patchTask(ctx context.Context, task *api.Task, taskPatch *api.T
}
taskPatched = t
}
-
- // trigger task check
- payload, err = json.Marshal(api.TaskCheckEarliestAllowedTimePayload{
- EarliestAllowedTs: *taskPatch.EarliestAllowedTs,
- })
- if err != nil {
- return nil, echo.NewHTTPError(http.StatusInternalServerError, errors.Wrapf(err, "failed to marshal statement advise payload: %v", task.Name))
- }
- _, err = s.store.CreateTaskCheckRunIfNeeded(ctx, &api.TaskCheckRunCreate{
- CreatorID: api.SystemBotID,
- TaskID: task.ID,
- Type: api.TaskCheckGeneralEarliestAllowedTime,
- Payload: string(payload),
- SkipIfAlreadyTerminated: false,
- })
- if err != nil {
- // It's OK if we failed to trigger a check, just emit an error log
- log.Error("Failed to trigger timing check after changing task earliest allowed time",
- zap.Int("task_id", task.ID),
- zap.String("task_name", task.Name),
- zap.Error(err),
- )
- }
}
return taskPatched, nil
}
@@ -826,11 +802,10 @@ func (s *Server) triggerDatabaseStatementAdviseTask(ctx context.Context, stateme
}
if _, err := s.store.CreateTaskCheckRunIfNeeded(ctx, &api.TaskCheckRunCreate{
- CreatorID: api.SystemBotID,
- TaskID: task.ID,
- Type: api.TaskCheckDatabaseStatementAdvise,
- Payload: string(payload),
- SkipIfAlreadyTerminated: false,
+ CreatorID: api.SystemBotID,
+ TaskID: task.ID,
+ Type: api.TaskCheckDatabaseStatementAdvise,
+ Payload: string(payload),
}); err != nil {
// It's OK if we failed to trigger a check, just emit an error log
log.Error("Failed to trigger statement advise task after changing task statement",
diff --git a/server/task_check_executor_timing.go b/server/task_check_executor_timing.go
deleted file mode 100644
index b47289cd29..0000000000
--- a/server/task_check_executor_timing.go
+++ /dev/null
@@ -1,65 +0,0 @@
-package server
-
-import (
- "context"
- "encoding/json"
- "fmt"
- "time"
-
- "github.com/bytebase/bytebase/api"
- "github.com/bytebase/bytebase/common"
-)
-
-// NewTaskCheckTimingExecutor creates a task check timing executor.
-func NewTaskCheckTimingExecutor() TaskCheckExecutor {
- return &TaskCheckTimingExecutor{}
-}
-
-// TaskCheckTimingExecutor is the task check timing executor.
-type TaskCheckTimingExecutor struct {
-}
-
-const dataFormat = "2006-01-02 15:04:05"
-
-// Run will run the task check timing executor once.
-func (*TaskCheckTimingExecutor) Run(_ context.Context, _ *Server, taskCheckRun *api.TaskCheckRun) (result []api.TaskCheckResult, err error) {
- payload := &api.TaskCheckEarliestAllowedTimePayload{}
- if err := json.Unmarshal([]byte(taskCheckRun.Payload), payload); err != nil {
- return []api.TaskCheckResult{}, common.Wrapf(err, common.Invalid, "invalid check timing payload")
- }
-
- if payload.EarliestAllowedTs == 0 {
- return []api.TaskCheckResult{
- {
- Status: api.TaskCheckStatusSuccess,
- Namespace: api.BBNamespace,
- Code: common.Ok.Int(),
- Title: "OK",
- Content: "Earliest allowed time is not set",
- },
- }, nil
- }
-
- // EarliestAllowedTs is store in UTC+0000
- if time.Now().UTC().Before(time.Unix(payload.EarliestAllowedTs, 0).UTC()) {
- return []api.TaskCheckResult{
- {
- Status: api.TaskCheckStatusWarn,
- Namespace: api.BBNamespace,
- Code: common.TaskTimingNotAllowed.Int(),
- Title: "Not ready to run",
- Content: fmt.Sprintf("Need to wait until the configured earliest running time: %s (UTC+0000)", time.Unix(payload.EarliestAllowedTs, 0).UTC().Format(dataFormat)),
- },
- }, nil
- }
-
- return []api.TaskCheckResult{
- {
- Status: api.TaskCheckStatusSuccess,
- Namespace: api.BBNamespace,
- Code: common.Ok.Int(),
- Title: "OK",
- Content: fmt.Sprintf("Passed the configured earliest running time: %s (UTC+0000)", time.Unix(payload.EarliestAllowedTs, 0).UTC().Format(dataFormat)),
- },
- }, nil
-}
diff --git a/server/task_check_scheduler.go b/server/task_check_scheduler.go
index 15a7ba6929..e87a3f2095 100644
--- a/server/task_check_scheduler.go
+++ b/server/task_check_scheduler.go
@@ -178,59 +178,13 @@ func (s *TaskCheckScheduler) Register(taskType api.TaskCheckType, executor TaskC
s.executors[taskType] = executor
}
-// Returns true if we meet either of the following conditions:
-// 1. Task has a non-default value and no task check has run before (so we are about to kick off the check for the first time)
-// 2. The specified EarliestAllowedTs has elapsed, so we need to rerun the check to unblock the task.
-//
-// On the other hand, we would also rerun the check if user has modified EarliestAllowedTs. This is handled separately in the task patch handler.
-func (s *TaskCheckScheduler) shouldScheduleTimingTaskCheck(ctx context.Context, task *api.Task, forceSchedule bool) (bool, error) {
- statusList := []api.TaskCheckRunStatus{api.TaskCheckRunDone, api.TaskCheckRunFailed, api.TaskCheckRunRunning}
- taskCheckType := api.TaskCheckGeneralEarliestAllowedTime
- taskCheckRunFind := &api.TaskCheckRunFind{
- TaskID: &task.ID,
- Type: &taskCheckType,
- StatusList: &statusList,
- Latest: true,
- }
- taskCheckRunList, err := s.server.store.FindTaskCheckRun(ctx, taskCheckRunFind)
- if err != nil {
- return false, err
- }
-
- // If there is not any task check scheduled before, we should only schedule one if user has specified a non-default value.
- if len(taskCheckRunList) == 0 {
- return task.EarliestAllowedTs != 0, nil
- }
-
- if forceSchedule {
- return true, nil
- }
-
- if time.Now().After(time.Unix(task.EarliestAllowedTs, 0)) {
- checkResult := &api.TaskCheckRunResultPayload{}
- if err := json.Unmarshal([]byte(taskCheckRunList[0].Result), checkResult); err != nil {
- return false, err
- }
- if checkResult.ResultList[0].Status == api.TaskCheckStatusSuccess {
- return false, nil
- }
- return true, nil
- }
-
- return false, nil
-}
-
// ScheduleCheckIfNeeded schedules a check if needed.
-func (s *TaskCheckScheduler) ScheduleCheckIfNeeded(ctx context.Context, task *api.Task, creatorID int, skipIfAlreadyTerminated bool) (*api.Task, error) {
- if err := s.scheduleTimingTaskCheck(ctx, task, creatorID, skipIfAlreadyTerminated); err != nil {
- return nil, errors.Wrap(err, "failed to schedule timing task check")
- }
-
- if err := s.scheduleLGTMTaskCheck(ctx, task, creatorID, skipIfAlreadyTerminated); err != nil {
+func (s *TaskCheckScheduler) ScheduleCheckIfNeeded(ctx context.Context, task *api.Task, creatorID int) (*api.Task, error) {
+ if err := s.scheduleLGTMTaskCheck(ctx, task, creatorID); err != nil {
return nil, errors.Wrap(err, "failed to schedule LGTM task check")
}
- if err := s.schedulePITRTaskCheck(ctx, task, creatorID, skipIfAlreadyTerminated); err != nil {
+ if err := s.schedulePITRTaskCheck(ctx, task, creatorID); err != nil {
return nil, errors.Wrap(err, "failed to schedule backup/PITR task check")
}
@@ -238,11 +192,11 @@ func (s *TaskCheckScheduler) ScheduleCheckIfNeeded(ctx context.Context, task *ap
return task, nil
}
- if err := s.scheduleGeneralTaskCheck(ctx, task, creatorID, skipIfAlreadyTerminated); err != nil {
+ if err := s.scheduleGeneralTaskCheck(ctx, task, creatorID); err != nil {
return nil, errors.Wrap(err, "failed to schedule general task check")
}
- if err := s.scheduleGhostTaskCheck(ctx, task, creatorID, skipIfAlreadyTerminated); err != nil {
+ if err := s.scheduleGhostTaskCheck(ctx, task, creatorID); err != nil {
return nil, errors.Wrap(err, "failed to schedule gh-ost task check")
}
@@ -258,15 +212,15 @@ func (s *TaskCheckScheduler) ScheduleCheckIfNeeded(ctx context.Context, task *ap
return nil, errors.Errorf("database ID not found %v", task.DatabaseID)
}
- if err := s.scheduleSyntaxCheckTaskCheck(ctx, task, creatorID, skipIfAlreadyTerminated, database, statement); err != nil {
+ if err := s.scheduleSyntaxCheckTaskCheck(ctx, task, creatorID, database, statement); err != nil {
return nil, errors.Wrap(err, "failed to schedule syntax check task check")
}
- if err := s.scheduleSQLReviewTaskCheck(ctx, task, creatorID, skipIfAlreadyTerminated, database, statement); err != nil {
+ if err := s.scheduleSQLReviewTaskCheck(ctx, task, creatorID, database, statement); err != nil {
return nil, errors.Wrap(err, "failed to schedule SQL review task check")
}
- if err := s.scheduleStmtTypeTaskCheck(ctx, task, creatorID, skipIfAlreadyTerminated, database, statement); err != nil {
+ if err := s.scheduleStmtTypeTaskCheck(ctx, task, creatorID, database, statement); err != nil {
return nil, errors.Wrap(err, "failed to schedule statement type task check")
}
@@ -306,7 +260,8 @@ func (*TaskCheckScheduler) getStatement(task *api.Task) (string, error) {
return "", errors.Errorf("invalid task type %s", task.Type)
}
}
-func (s *TaskCheckScheduler) scheduleStmtTypeTaskCheck(ctx context.Context, task *api.Task, creatorID int, skipIfAlreadyTerminated bool, database *api.Database, statement string) error {
+
+func (s *TaskCheckScheduler) scheduleStmtTypeTaskCheck(ctx context.Context, task *api.Task, creatorID int, database *api.Database, statement string) error {
if !api.IsStatementTypeCheckSupported(database.Instance.Engine) {
return nil
}
@@ -320,17 +275,17 @@ func (s *TaskCheckScheduler) scheduleStmtTypeTaskCheck(ctx context.Context, task
return errors.Wrapf(err, "failed to marshal statement type payload: %v", task.Name)
}
if _, err := s.server.store.CreateTaskCheckRunIfNeeded(ctx, &api.TaskCheckRunCreate{
- CreatorID: creatorID,
- TaskID: task.ID,
- Type: api.TaskCheckDatabaseStatementType,
- Payload: string(payload),
- SkipIfAlreadyTerminated: skipIfAlreadyTerminated,
+ CreatorID: creatorID,
+ TaskID: task.ID,
+ Type: api.TaskCheckDatabaseStatementType,
+ Payload: string(payload),
}); err != nil {
return err
}
return nil
}
-func (s *TaskCheckScheduler) scheduleSQLReviewTaskCheck(ctx context.Context, task *api.Task, creatorID int, skipIfAlreadyTerminated bool, database *api.Database, statement string) error {
+
+func (s *TaskCheckScheduler) scheduleSQLReviewTaskCheck(ctx context.Context, task *api.Task, creatorID int, database *api.Database, statement string) error {
if !api.IsSQLReviewSupported(database.Instance.Engine, s.server.profile.Mode) {
return nil
}
@@ -349,17 +304,17 @@ func (s *TaskCheckScheduler) scheduleSQLReviewTaskCheck(ctx context.Context, tas
return errors.Wrapf(err, "failed to marshal statement advise payload: %v", task.Name)
}
if _, err := s.server.store.CreateTaskCheckRunIfNeeded(ctx, &api.TaskCheckRunCreate{
- CreatorID: creatorID,
- TaskID: task.ID,
- Type: api.TaskCheckDatabaseStatementAdvise,
- Payload: string(payload),
- SkipIfAlreadyTerminated: skipIfAlreadyTerminated,
+ CreatorID: creatorID,
+ TaskID: task.ID,
+ Type: api.TaskCheckDatabaseStatementAdvise,
+ Payload: string(payload),
}); err != nil {
return err
}
return nil
}
-func (s *TaskCheckScheduler) scheduleSyntaxCheckTaskCheck(ctx context.Context, task *api.Task, creatorID int, skipIfAlreadyTerminated bool, database *api.Database, statement string) error {
+
+func (s *TaskCheckScheduler) scheduleSyntaxCheckTaskCheck(ctx context.Context, task *api.Task, creatorID int, database *api.Database, statement string) error {
if !api.IsSyntaxCheckSupported(database.Instance.Engine, s.server.profile.Mode) {
return nil
}
@@ -373,32 +328,29 @@ func (s *TaskCheckScheduler) scheduleSyntaxCheckTaskCheck(ctx context.Context, t
return errors.Wrapf(err, "failed to marshal statement advise payload: %v", task.Name)
}
if _, err := s.server.store.CreateTaskCheckRunIfNeeded(ctx, &api.TaskCheckRunCreate{
- CreatorID: creatorID,
- TaskID: task.ID,
- Type: api.TaskCheckDatabaseStatementSyntax,
- Payload: string(payload),
- SkipIfAlreadyTerminated: skipIfAlreadyTerminated,
+ CreatorID: creatorID,
+ TaskID: task.ID,
+ Type: api.TaskCheckDatabaseStatementSyntax,
+ Payload: string(payload),
}); err != nil {
return err
}
return nil
}
-func (s *TaskCheckScheduler) scheduleGeneralTaskCheck(ctx context.Context, task *api.Task, creatorID int, skipIfAlreadyTerminated bool) error {
+func (s *TaskCheckScheduler) scheduleGeneralTaskCheck(ctx context.Context, task *api.Task, creatorID int) error {
if _, err := s.server.store.CreateTaskCheckRunIfNeeded(ctx, &api.TaskCheckRunCreate{
- CreatorID: creatorID,
- TaskID: task.ID,
- Type: api.TaskCheckDatabaseConnect,
- SkipIfAlreadyTerminated: skipIfAlreadyTerminated,
+ CreatorID: creatorID,
+ TaskID: task.ID,
+ Type: api.TaskCheckDatabaseConnect,
}); err != nil {
return err
}
if _, err := s.server.store.CreateTaskCheckRunIfNeeded(ctx, &api.TaskCheckRunCreate{
- CreatorID: creatorID,
- TaskID: task.ID,
- Type: api.TaskCheckInstanceMigrationSchema,
- SkipIfAlreadyTerminated: skipIfAlreadyTerminated,
+ CreatorID: creatorID,
+ TaskID: task.ID,
+ Type: api.TaskCheckInstanceMigrationSchema,
}); err != nil {
return err
}
@@ -406,64 +358,35 @@ func (s *TaskCheckScheduler) scheduleGeneralTaskCheck(ctx context.Context, task
return nil
}
-func (s *TaskCheckScheduler) scheduleGhostTaskCheck(ctx context.Context, task *api.Task, creatorID int, skipIfAlreadyTerminated bool) error {
+func (s *TaskCheckScheduler) scheduleGhostTaskCheck(ctx context.Context, task *api.Task, creatorID int) error {
if task.Type != api.TaskDatabaseSchemaUpdateGhostSync {
return nil
}
if _, err := s.server.store.CreateTaskCheckRunIfNeeded(ctx, &api.TaskCheckRunCreate{
- CreatorID: creatorID,
- TaskID: task.ID,
- Type: api.TaskCheckGhostSync,
- SkipIfAlreadyTerminated: skipIfAlreadyTerminated,
+ CreatorID: creatorID,
+ TaskID: task.ID,
+ Type: api.TaskCheckGhostSync,
}); err != nil {
return err
}
return nil
}
-func (s *TaskCheckScheduler) schedulePITRTaskCheck(ctx context.Context, task *api.Task, creatorID int, skipIfAlreadyTerminated bool) error {
+func (s *TaskCheckScheduler) schedulePITRTaskCheck(ctx context.Context, task *api.Task, creatorID int) error {
if task.Type != api.TaskDatabaseRestorePITRRestore {
return nil
}
if _, err := s.server.store.CreateTaskCheckRunIfNeeded(ctx, &api.TaskCheckRunCreate{
- CreatorID: creatorID,
- TaskID: task.ID,
- Type: api.TaskCheckPITRMySQL,
- SkipIfAlreadyTerminated: skipIfAlreadyTerminated,
- }); err != nil {
- return err
- }
- return nil
-}
-
-func (s *TaskCheckScheduler) scheduleTimingTaskCheck(ctx context.Context, task *api.Task, creatorID int, skipIfAlreadyTerminated bool) error {
- // we only set skipIfAlreadyTerminated to false when user explicitly want to reschedule a taskCheck
- ok, err := s.shouldScheduleTimingTaskCheck(ctx, task, !skipIfAlreadyTerminated /* forceSchedule */)
- if err != nil {
- return err
- }
- if !ok {
- return nil
- }
- taskCheckPayload, err := json.Marshal(api.TaskCheckEarliestAllowedTimePayload{
- EarliestAllowedTs: task.EarliestAllowedTs,
- })
- if err != nil {
- return err
- }
- if _, err := s.server.store.CreateTaskCheckRunIfNeeded(ctx, &api.TaskCheckRunCreate{
- CreatorID: creatorID,
- TaskID: task.ID,
- Type: api.TaskCheckGeneralEarliestAllowedTime,
- Payload: string(taskCheckPayload),
- SkipIfAlreadyTerminated: false,
+ CreatorID: creatorID,
+ TaskID: task.ID,
+ Type: api.TaskCheckPITRMySQL,
}); err != nil {
return err
}
return nil
}
-func (s *TaskCheckScheduler) scheduleLGTMTaskCheck(ctx context.Context, task *api.Task, creatorID int, skipIfAlreadyTerminated bool) error {
+func (s *TaskCheckScheduler) scheduleLGTMTaskCheck(ctx context.Context, task *api.Task, creatorID int) error {
if !s.server.feature(api.FeatureLGTM) {
return nil
}
@@ -480,10 +403,9 @@ func (s *TaskCheckScheduler) scheduleLGTMTaskCheck(ctx context.Context, task *ap
return nil
}
if _, err := s.server.store.CreateTaskCheckRunIfNeeded(ctx, &api.TaskCheckRunCreate{
- CreatorID: creatorID,
- TaskID: task.ID,
- Type: api.TaskCheckIssueLGTM,
- SkipIfAlreadyTerminated: skipIfAlreadyTerminated,
+ CreatorID: creatorID,
+ TaskID: task.ID,
+ Type: api.TaskCheckIssueLGTM,
}); err != nil {
return err
}
diff --git a/store/task_check_run.go b/store/task_check_run.go
index d46eb50fe3..7c681c1d25 100644
--- a/store/task_check_run.go
+++ b/store/task_check_run.go
@@ -137,11 +137,6 @@ func (s *Store) createTaskCheckRunRawIfNeeded(ctx context.Context, create *api.T
defer tx.Rollback()
statusList := []api.TaskCheckRunStatus{api.TaskCheckRunRunning}
- if create.SkipIfAlreadyTerminated {
- statusList = append(statusList, api.TaskCheckRunDone)
- statusList = append(statusList, api.TaskCheckRunFailed)
- statusList = append(statusList, api.TaskCheckRunCanceled)
- }
taskCheckRunFind := &api.TaskCheckRunFind{
TaskID: &create.TaskID,
Type: &create.Type,
@@ -153,21 +148,7 @@ func (s *Store) createTaskCheckRunRawIfNeeded(ctx context.Context, create *api.T
return nil, err
}
- runningCount := 0
- if create.SkipIfAlreadyTerminated {
- for _, taskCheckRun := range taskCheckRunList {
- switch taskCheckRun.Status {
- case api.TaskCheckRunDone, api.TaskCheckRunFailed, api.TaskCheckRunCanceled:
- return taskCheckRun, nil
- case api.TaskCheckRunRunning:
- runningCount++
- }
- }
- } else {
- runningCount = len(taskCheckRunList)
- }
-
- if runningCount > 0 {
+ if runningCount := len(taskCheckRunList); runningCount > 0 {
if runningCount > 1 {
// Normally, this should not happen, if it occurs, emit a warning
log.Warn(fmt.Sprintf("Found %d task check run, expect at most 1", len(taskCheckRunList)),