Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
Inspect all open pipelines and schedule the next PENDING task if applicable
天舟c3e47d14517a
diff --git a/backend/api/pipeline.go b/backend/api/pipeline.goindex 049f714047..1d69f52a57 100644--- a/backend/api/pipeline.go+++ b/backend/api/pipeline.go@@ -59,6 +59,9 @@ type PipelineCreate struct {type PipelineFind struct {ID *int++ // Domain specific fields+ Status *PipelineStatus}func (find *PipelineFind) String() string {@@ -82,6 +85,7 @@ type PipelinePatch struct {type PipelineService interface {CreatePipeline(ctx context.Context, create *PipelineCreate) (*Pipeline, error)+ FindPipelineList(ctx context.Context, find *PipelineFind) ([]*Pipeline, error)FindPipeline(ctx context.Context, find *PipelineFind) (*Pipeline, error)PatchPipeline(ctx context.Context, patch *PipelinePatch) (*Pipeline, error)}diff --git a/backend/api/task.go b/backend/api/task.goindex b72b98b43d..9a82a4a56e 100644--- a/backend/api/task.go+++ b/backend/api/task.go@@ -34,10 +34,6 @@ func (e TaskStatus) String() string {return "UNKNOWN"}-func (e TaskStatus) IsEndStatus() bool {- return e == TaskDone-}-type TaskType stringconst (diff --git a/backend/server/issue.go b/backend/server/issue.goindex fd19d2859d..5b40a4d37d 100644--- a/backend/server/issue.go+++ b/backend/server/issue.go@@ -296,11 +296,11 @@ func (s *Server) registerIssueRoutes(g *echo.Group) {case api.Issue_Open:pipelineStatus = api.Pipeline_Opencase api.Issue_Done:- // Returns error if any of the tasks is not in the end status.+ // Returns error if any of the tasks is not DONE.for _, stage := range issue.Pipeline.StageList {for _, task := range stage.TaskList {- if !task.Status.IsEndStatus() {- return echo.NewHTTPError(http.StatusConflict, fmt.Sprintf("Failed to resolve issue: %v. Task %v is in %v status.", issue.Name, task.Name, task.Status))+ if task.Status != api.TaskDone {+ return echo.NewHTTPError(http.StatusConflict, fmt.Sprintf("Failed to resolve issue: %v. Task %v has not finished", issue.Name, task.Name))}}}@@ -313,7 +313,7 @@ func (s *Server) registerIssueRoutes(g *echo.Group) {for _, task := range stage.TaskList {if task.Status == api.TaskRunning {if _, err := s.ChangeTaskStatus(context.Background(), task, api.TaskCanceled, c.Get(GetPrincipalIdContextKey()).(int)); err != nil {- return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to cancel issue: %v. Failed to cancel task: %v.", issue.Name, task.Name)).SetInternal(err)+ return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to cancel issue: %v. Failed to cancel task: %v", issue.Name, task.Name)).SetInternal(err)}}}diff --git a/backend/server/task_scheduler.go b/backend/server/task_scheduler.goindex eb388bcc17..0b1f6c2e3d 100644--- a/backend/server/task_scheduler.go+++ b/backend/server/task_scheduler.go@@ -43,16 +43,49 @@ func (s *TaskScheduler) Run() error {s.l.Error("Scheduler PANIC RECOVER", zap.Error(err))}}()- status := api.TaskRunning++ // Inspect all open pipelines and schedule the next PENDING task if applicable+ pipelineStatus := api.Pipeline_Open+ pipelineFind := &api.PipelineFind{+ Status: &pipelineStatus,+ }+ pipelineList, err := s.server.PipelineService.FindPipelineList(context.Background(), pipelineFind)+ if err != nil {+ s.l.Info(fmt.Sprintf("Failed to retrieve open pipelines: %v\n", err))+ }+ for _, pipeline := range pipelineList {+ if err := s.server.ComposePipelineRelationship(context.Background(), pipeline, []string{}); err != nil {+ s.l.Info(fmt.Sprintf("Failed to fetch stage info for pipeline: %v. Error: %v", pipeline.Name, err))+ continue+ }++ for _, stage := range pipeline.StageList {+ for _, task := range stage.TaskList {+ if task.Status != api.TaskDone {+ if task.Status == api.TaskPending {+ _, err = s.Schedule(context.Background(), task)+ if err != nil {+ s.l.Info(fmt.Sprintf("Failed to schedule next running task: %v. Error: %v", task.Name, err))+ }+ }+ goto PIPELINE_END+ }+ }+ }+ PIPELINE_END:+ }++ // Inspect all running tasks+ taskStatus := api.TaskRunningtaskFind := &api.TaskFind{- Status: &status,+ Status: &taskStatus,}- list, err := s.server.TaskService.FindTaskList(context.Background(), taskFind)+ taskList, err := s.server.TaskService.FindTaskList(context.Background(), taskFind)if err != nil {s.l.Info(fmt.Sprintf("Failed to retrieve running tasks: %v\n", err))}- for _, task := range list {+ for _, task := range taskList {executor, ok := s.executors[string(task.Type)]if !ok {s.l.Info(fmt.Sprintf("Unknown task type: %v. Skip.", task.Type))diff --git a/backend/store/pipeline.go b/backend/store/pipeline.goindex 298d218a33..e28b6cccb5 100644--- a/backend/store/pipeline.go+++ b/backend/store/pipeline.go@@ -45,6 +45,22 @@ func (s *PipelineService) CreatePipeline(ctx context.Context, create *api.Pipelireturn pipeline, nil}+// FindPipelineList retrieves a list of pipelines based on find.+func (s *PipelineService) FindPipelineList(ctx context.Context, find *api.PipelineFind) ([]*api.Pipeline, error) {+ tx, err := s.db.BeginTx(ctx, nil)+ if err != nil {+ return nil, FormatError(err)+ }+ defer tx.Rollback()++ list, err := s.findPipelineList(ctx, tx, find)+ if err != nil {+ return []*api.Pipeline{}, err+ }++ return list, nil+}+// FindPipeline retrieves a single pipeline based on find.// Returns ENOTFOUND if no matching record.// Returns the first matching one and prints a warning if finding more than 1 matching records.@@ -132,6 +148,9 @@ func (s *PipelineService) findPipelineList(ctx context.Context, tx *Tx, find *apif v := find.ID; v != nil {where, args = append(where, "id = ?"), append(args, *v)}+ if v := find.Status; v != nil {+ where, args = append(where, "`status` = ?"), append(args, *v)+ }rows, err := tx.QueryContext(ctx, `SELECT