klesh commented on code in PR #3764:
URL: 
https://github.com/apache/incubator-devlake/pull/3764#discussion_r1030226235


##########
services/pipeline.go:
##########
@@ -165,29 +167,57 @@ func RunPipelineInQueue(pipelineMaxParallel int64) {
                }
                globalPipelineLog.Info("get lock and wait next pipeline")
                dbPipeline := &models.DbPipeline{}
+               var dbLabels []models.DbPipelineLabel
                for {
                        cronLocker.Lock()
+                       // prepare query to find an appropriate pipeline to 
execute
                        db.Where("status IN ?", []string{models.TASK_CREATED, 
models.TASK_RERUN}).
+                               Joins(`left join _devlake_pipeline_labels ON
+                  _devlake_pipeline_labels.pipeline_id = _devlake_pipelines.id 
AND
+                  _devlake_pipeline_labels.name LIKE 'parallel/%' AND
+                  _devlake_pipeline_labels.name in ?`, runningParallelLabels).
+                               Group(`id`).
+                               
Having(`count(_devlake_pipeline_labels.name)=0`).
+                               Select("id").
                                Order("id ASC").Limit(1).Find(dbPipeline)
                        cronLocker.Unlock()
                        if dbPipeline.ID != 0 {
-                               db.Model(&models.DbPipeline{}).Where("id = ?", 
dbPipeline.ID).Updates(map[string]interface{}{
-                                       "status":   models.TASK_RUNNING,
-                                       "message":  "",
-                                       "began_at": time.Now(),
-                               })
                                break
                        }
                        time.Sleep(time.Second)
                }
-               go func(pipelineId uint64) {
+
+               db.Model(&models.DbPipeline{}).Where("id = ?", 
dbPipeline.ID).Updates(map[string]interface{}{
+                       "status":   models.TASK_RUNNING,
+                       "message":  "",
+                       "began_at": time.Now(),
+               })
+               dbPipeline, dbLabels, err = GetDbPipeline(dbPipeline.ID)
+               if err != nil {
+                       panic(err)
+               }
+
+               // add pipelineParallelLabels to runningParallelLabels
+               var pipelineParallelLabels []string
+               for _, dbLabel := range dbLabels {
+                       if strings.HasPrefix(dbLabel.Name, `parallel/`) {
+                               pipelineParallelLabels = 
append(pipelineParallelLabels, dbLabel.Name)
+                       }
+               }
+               runningParallelLabels = append(runningParallelLabels, 
pipelineParallelLabels...)
+
+               go func(pipelineId uint64, parallelLabels []string) {
                        defer sema.Release(1)
-                       globalPipelineLog.Info("run pipeline, %d", pipelineId)
+                       defer func() {
+                               runningParallelLabels = 
utils.SliceRemove(runningParallelLabels, parallelLabels...)

Review Comment:
   This doesn't seem right.
   1. in previous step, the label was append to the slice without any 
deduplication
   2. and this function remove the labels by checking the content?
   
   I suggest that we create a struct to maintain `runningParallelLabels` 
separately, and more important, write UnitTest for it!



##########
services/pipeline.go:
##########
@@ -167,27 +171,58 @@ func RunPipelineInQueue(pipelineMaxParallel int64) {
                dbPipeline := &models.DbPipeline{}
                for {
                        cronLocker.Lock()
+                       // prepare query to find an appropriate pipeline to 
execute
                        db.Where("status IN ?", []string{models.TASK_CREATED, 
models.TASK_RERUN}).
+                               Joins(`left join _devlake_pipeline_labels ON
+                  _devlake_pipeline_labels.pipeline_id = _devlake_pipelines.id 
AND

Review Comment:
   The alignment is off



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to