You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@devlake.apache.org by GitBox <gi...@apache.org> on 2022/11/18 15:50:50 UTC

[GitHub] [incubator-devlake] likyh opened a new pull request, #3764: Issues/3234

likyh opened a new pull request, #3764:
URL: https://github.com/apache/incubator-devlake/pull/3764

   ### Summary
   What does this PR do?
   
   ### Does this close any open issues?
   Closes xx
   
   ### Screenshots
   Include any relevant screenshots here.
   
   ### Other Information
   Any other information that is important to this PR.
   


-- 
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: commits-unsubscribe@devlake.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-devlake] likyh commented on a diff in pull request #3764: Issues/3234 add parallelLabels for blueprint/pipeline

Posted by GitBox <gi...@apache.org>.
likyh commented on code in PR #3764:
URL: https://github.com/apache/incubator-devlake/pull/3764#discussion_r1027904098


##########
models/migrationscripts/20221115_add_parallel_labels.go:
##########
@@ -0,0 +1,69 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package migrationscripts
+
+import (
+	"github.com/apache/incubator-devlake/errors"
+	"github.com/apache/incubator-devlake/plugins/core"
+	"time"
+)
+
+type DbPipelineLabel20221115 struct {
+	CreatedAt  time.Time `json:"createdAt"`
+	UpdatedAt  time.Time `json:"updatedAt"`
+	PipelineId uint64    `json:"pipeline_id" gorm:"primaryKey"`
+	Name       string    `json:"name" gorm:"primaryKey"`
+}
+
+func (DbPipelineLabel20221115) TableName() string {
+	return "_devlake_pipeline_labels"
+}
+
+type DbBlueprintLabel20221115 struct {
+	CreatedAt   time.Time `json:"createdAt"`
+	UpdatedAt   time.Time `json:"updatedAt"`
+	BlueprintId uint64    `json:"blueprint_id" gorm:"primaryKey"`
+	Name        string    `json:"name" gorm:"primaryKey"`
+}
+
+func (DbBlueprintLabel20221115) TableName() string {
+	return "_devlake_blueprint_labels"
+}
+
+type addLabels struct{}
+
+func (*addLabels) Up(res core.BasicRes) errors.Error {
+	db := res.GetDal()
+	err := db.AutoMigrate(&DbPipelineLabel20221115{})
+	if err != nil {
+		return err
+	}
+	err = db.AutoMigrate(&DbBlueprintLabel20221115{})

Review Comment:
   good idea



-- 
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: commits-unsubscribe@devlake.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-devlake] klesh commented on a diff in pull request #3764: Issues/3234 add parallelLabels for blueprint/pipeline

Posted by GitBox <gi...@apache.org>.
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: commits-unsubscribe@devlake.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-devlake] likyh commented on a diff in pull request #3764: Issues/3234 add parallelLabels for blueprint/pipeline

Posted by GitBox <gi...@apache.org>.
likyh commented on code in PR #3764:
URL: https://github.com/apache/incubator-devlake/pull/3764#discussion_r1027640732


##########
models/migrationscripts/20221115_add_parallel_labels.go:
##########
@@ -0,0 +1,69 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package migrationscripts
+
+import (
+	"github.com/apache/incubator-devlake/errors"
+	"github.com/apache/incubator-devlake/plugins/core"
+	"time"
+)
+
+type DbPipelineParallelLabel20221115 struct {
+	CreatedAt  time.Time `json:"createdAt"`
+	UpdatedAt  time.Time `json:"updatedAt"`
+	PipelineId uint64    `json:"pipeline_id" gorm:"primaryKey"`
+	Name       string    `json:"name" gorm:"primaryKey"`
+}
+
+func (DbPipelineParallelLabel20221115) TableName() string {
+	return "_devlake_pipeline_parallel_labels"
+}
+
+type DbBlueprintParallelLabel20221115 struct {
+	CreatedAt   time.Time `json:"createdAt"`
+	UpdatedAt   time.Time `json:"updatedAt"`
+	BlueprintId uint64    `json:"blueprint_id" gorm:"primaryKey"`
+	Name        string    `json:"name" gorm:"primaryKey"`
+}
+
+func (DbBlueprintParallelLabel20221115) TableName() string {
+	return "_devlake_blueprint_parallel_labels"
+}
+
+type addParallelLabels struct{}
+
+func (*addParallelLabels) Up(res core.BasicRes) errors.Error {
+	db := res.GetDal()
+	err := db.AutoMigrate(&DbPipelineParallelLabel20221115{})
+	if err != nil {
+		return err
+	}
+	err = db.AutoMigrate(&DbBlueprintParallelLabel20221115{})
+	if err != nil {
+		return err
+	}
+	return nil
+}
+
+func (*addParallelLabels) Version() uint64 {
+	return 20221115000034
+}
+
+func (*addParallelLabels) Name() string {
+	return "UpdateSchemas for addParallelLabels"

Review Comment:
   fixed



-- 
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: commits-unsubscribe@devlake.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-devlake] warren830 commented on a diff in pull request #3764: Issues/3234 add parallelLabels for blueprint/pipeline

Posted by GitBox <gi...@apache.org>.
warren830 commented on code in PR #3764:
URL: https://github.com/apache/incubator-devlake/pull/3764#discussion_r1027464493


##########
models/migrationscripts/20221115_add_parallel_labels.go:
##########
@@ -0,0 +1,69 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package migrationscripts
+
+import (
+	"github.com/apache/incubator-devlake/errors"
+	"github.com/apache/incubator-devlake/plugins/core"
+	"time"
+)
+
+type DbPipelineParallelLabel20221115 struct {
+	CreatedAt  time.Time `json:"createdAt"`
+	UpdatedAt  time.Time `json:"updatedAt"`
+	PipelineId uint64    `json:"pipeline_id" gorm:"primaryKey"`
+	Name       string    `json:"name" gorm:"primaryKey"`
+}
+
+func (DbPipelineParallelLabel20221115) TableName() string {
+	return "_devlake_pipeline_parallel_labels"
+}
+
+type DbBlueprintParallelLabel20221115 struct {
+	CreatedAt   time.Time `json:"createdAt"`
+	UpdatedAt   time.Time `json:"updatedAt"`
+	BlueprintId uint64    `json:"blueprint_id" gorm:"primaryKey"`
+	Name        string    `json:"name" gorm:"primaryKey"`
+}
+
+func (DbBlueprintParallelLabel20221115) TableName() string {
+	return "_devlake_blueprint_parallel_labels"
+}
+
+type addParallelLabels struct{}
+
+func (*addParallelLabels) Up(res core.BasicRes) errors.Error {
+	db := res.GetDal()
+	err := db.AutoMigrate(&DbPipelineParallelLabel20221115{})
+	if err != nil {
+		return err
+	}
+	err = db.AutoMigrate(&DbBlueprintParallelLabel20221115{})

Review Comment:
   why there are two automigrate for the same table?



-- 
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: commits-unsubscribe@devlake.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-devlake] likyh commented on a diff in pull request #3764: Issues/3234 add parallelLabels for blueprint/pipeline

Posted by GitBox <gi...@apache.org>.
likyh commented on code in PR #3764:
URL: https://github.com/apache/incubator-devlake/pull/3764#discussion_r1027917787


##########
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:
   fix, add lock for this



-- 
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: commits-unsubscribe@devlake.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-devlake] warren830 commented on a diff in pull request #3764: Issues/3234 add parallelLabels for blueprint/pipeline

Posted by GitBox <gi...@apache.org>.
warren830 commented on code in PR #3764:
URL: https://github.com/apache/incubator-devlake/pull/3764#discussion_r1027464691


##########
models/migrationscripts/20221115_add_parallel_labels.go:
##########
@@ -0,0 +1,69 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package migrationscripts
+
+import (
+	"github.com/apache/incubator-devlake/errors"
+	"github.com/apache/incubator-devlake/plugins/core"
+	"time"
+)
+
+type DbPipelineParallelLabel20221115 struct {
+	CreatedAt  time.Time `json:"createdAt"`
+	UpdatedAt  time.Time `json:"updatedAt"`
+	PipelineId uint64    `json:"pipeline_id" gorm:"primaryKey"`
+	Name       string    `json:"name" gorm:"primaryKey"`
+}
+
+func (DbPipelineParallelLabel20221115) TableName() string {
+	return "_devlake_pipeline_parallel_labels"
+}
+
+type DbBlueprintParallelLabel20221115 struct {
+	CreatedAt   time.Time `json:"createdAt"`
+	UpdatedAt   time.Time `json:"updatedAt"`
+	BlueprintId uint64    `json:"blueprint_id" gorm:"primaryKey"`
+	Name        string    `json:"name" gorm:"primaryKey"`
+}
+
+func (DbBlueprintParallelLabel20221115) TableName() string {
+	return "_devlake_blueprint_parallel_labels"
+}
+
+type addParallelLabels struct{}
+
+func (*addParallelLabels) Up(res core.BasicRes) errors.Error {
+	db := res.GetDal()
+	err := db.AutoMigrate(&DbPipelineParallelLabel20221115{})
+	if err != nil {
+		return err
+	}
+	err = db.AutoMigrate(&DbBlueprintParallelLabel20221115{})
+	if err != nil {
+		return err
+	}
+	return nil
+}
+
+func (*addParallelLabels) Version() uint64 {
+	return 20221115000034
+}
+
+func (*addParallelLabels) Name() string {
+	return "UpdateSchemas for addParallelLabels"

Review Comment:
   `add _devlake_blueprint_parallel_labels` is better?



-- 
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: commits-unsubscribe@devlake.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-devlake] warren830 commented on a diff in pull request #3764: Issues/3234 add parallelLabels for blueprint/pipeline

Posted by GitBox <gi...@apache.org>.
warren830 commented on code in PR #3764:
URL: https://github.com/apache/incubator-devlake/pull/3764#discussion_r1027465324


##########
models/migrationscripts/20221115_add_parallel_labels.go:
##########
@@ -0,0 +1,69 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package migrationscripts
+
+import (
+	"github.com/apache/incubator-devlake/errors"
+	"github.com/apache/incubator-devlake/plugins/core"
+	"time"
+)
+
+type DbPipelineParallelLabel20221115 struct {
+	CreatedAt  time.Time `json:"createdAt"`
+	UpdatedAt  time.Time `json:"updatedAt"`
+	PipelineId uint64    `json:"pipeline_id" gorm:"primaryKey"`
+	Name       string    `json:"name" gorm:"primaryKey"`
+}
+
+func (DbPipelineParallelLabel20221115) TableName() string {
+	return "_devlake_pipeline_parallel_labels"
+}
+
+type DbBlueprintParallelLabel20221115 struct {
+	CreatedAt   time.Time `json:"createdAt"`
+	UpdatedAt   time.Time `json:"updatedAt"`
+	BlueprintId uint64    `json:"blueprint_id" gorm:"primaryKey"`
+	Name        string    `json:"name" gorm:"primaryKey"`
+}
+
+func (DbBlueprintParallelLabel20221115) TableName() string {
+	return "_devlake_blueprint_parallel_labels"
+}
+
+type addParallelLabels struct{}
+
+func (*addParallelLabels) Up(res core.BasicRes) errors.Error {
+	db := res.GetDal()
+	err := db.AutoMigrate(&DbPipelineParallelLabel20221115{})
+	if err != nil {
+		return err
+	}
+	err = db.AutoMigrate(&DbBlueprintParallelLabel20221115{})
+	if err != nil {
+		return err
+	}
+	return nil
+}
+
+func (*addParallelLabels) Version() uint64 {
+	return 20221115000034
+}
+
+func (*addParallelLabels) Name() string {
+	return "UpdateSchemas for addParallelLabels"

Review Comment:
   what about `add parallel labels' schema for blueprint and pipeline`



-- 
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: commits-unsubscribe@devlake.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-devlake] mappjzc commented on a diff in pull request #3764: Issues/3234 add parallelLabels for blueprint/pipeline

Posted by GitBox <gi...@apache.org>.
mappjzc commented on code in PR #3764:
URL: https://github.com/apache/incubator-devlake/pull/3764#discussion_r1027761590


##########
models/migrationscripts/20221115_add_parallel_labels.go:
##########
@@ -0,0 +1,69 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package migrationscripts
+
+import (
+	"github.com/apache/incubator-devlake/errors"
+	"github.com/apache/incubator-devlake/plugins/core"
+	"time"
+)
+
+type DbPipelineLabel20221115 struct {
+	CreatedAt  time.Time `json:"createdAt"`
+	UpdatedAt  time.Time `json:"updatedAt"`
+	PipelineId uint64    `json:"pipeline_id" gorm:"primaryKey"`
+	Name       string    `json:"name" gorm:"primaryKey"`
+}
+
+func (DbPipelineLabel20221115) TableName() string {
+	return "_devlake_pipeline_labels"
+}
+
+type DbBlueprintLabel20221115 struct {
+	CreatedAt   time.Time `json:"createdAt"`
+	UpdatedAt   time.Time `json:"updatedAt"`
+	BlueprintId uint64    `json:"blueprint_id" gorm:"primaryKey"`
+	Name        string    `json:"name" gorm:"primaryKey"`
+}
+
+func (DbBlueprintLabel20221115) TableName() string {
+	return "_devlake_blueprint_labels"
+}
+
+type addLabels struct{}
+
+func (*addLabels) Up(res core.BasicRes) errors.Error {
+	db := res.GetDal()
+	err := db.AutoMigrate(&DbPipelineLabel20221115{})
+	if err != nil {
+		return err
+	}
+	err = db.AutoMigrate(&DbBlueprintLabel20221115{})

Review Comment:
   why don't use migrationhelper.AutoMigrateTables?



##########
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:
   The append and SliceRemove operations on runningParallelLabels are not thread safe.



-- 
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: commits-unsubscribe@devlake.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-devlake] klesh commented on a diff in pull request #3764: Issues/3234 add parallelLabels for blueprint/pipeline

Posted by GitBox <gi...@apache.org>.
klesh commented on code in PR #3764:
URL: https://github.com/apache/incubator-devlake/pull/3764#discussion_r1028739342


##########
models/blueprint.go:
##########
@@ -82,3 +83,14 @@ type DbBlueprint struct {
 func (DbBlueprint) TableName() string {
 	return "_devlake_blueprints"
 }
+
+type DbBlueprintLabel struct {
+	CreatedAt   time.Time `json:"createdAt"`
+	UpdatedAt   time.Time `json:"updatedAt"`
+	BlueprintId uint64    `json:"blueprint_id" gorm:"primaryKey"`
+	Name        string    `json:"name" gorm:"primaryKey"`

Review Comment:
   Maybe we should add an index for the `name` column?



##########
services/blueprint.go:
##########
@@ -206,29 +214,29 @@ func DeleteBlueprint(id uint64) errors.Error {
 
 // ReloadBlueprints FIXME ...
 func ReloadBlueprints(c *cron.Cron) errors.Error {
-	dbBlueprints := make([]*models.DbBlueprint, 0)
-	if err := db.Model(&models.DbBlueprint{}).
-		Where("enable = ? AND is_manual = ?", true, false).
-		Find(&dbBlueprints).Error; err != nil {
-		return errors.Internal.Wrap(err, "error finding blueprints while reloading")
+	enable := true
+	isManual := false
+	dbBlueprints, dbLabelsMap, _, err := GetDbBlueprints(&BlueprintQuery{Enable: &enable, IsManual: &isManual})

Review Comment:
   Maybe we should add a `Labels` property to `DbBlueprint` with `gorm:"-"` and let `GetDbBlueprints` `GetDbBlueprint` fill it for the callers



##########
models/pipeline.go:
##########
@@ -67,3 +69,14 @@ type DbPipeline struct {
 func (DbPipeline) TableName() string {
 	return "_devlake_pipelines"
 }
+
+type DbPipelineLabel struct {
+	CreatedAt  time.Time `json:"createdAt"`
+	UpdatedAt  time.Time `json:"updatedAt"`
+	PipelineId uint64    `json:"pipeline_id" gorm:"primaryKey"`
+	Name       string    `json:"name" gorm:"primaryKey"`

Review Comment:
   Same as above



##########
models/migrationscripts/20221115_add_parallel_labels.go:
##########
@@ -0,0 +1,69 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package migrationscripts
+
+import (
+	"github.com/apache/incubator-devlake/errors"
+	"github.com/apache/incubator-devlake/plugins/core"
+	"time"
+)
+
+type DbPipelineLabel20221115 struct {
+	CreatedAt  time.Time `json:"createdAt"`
+	UpdatedAt  time.Time `json:"updatedAt"`
+	PipelineId uint64    `json:"pipeline_id" gorm:"primaryKey"`
+	Name       string    `json:"name" gorm:"primaryKey"`

Review Comment:
   Same as above



-- 
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: commits-unsubscribe@devlake.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-devlake] likyh commented on a diff in pull request #3764: Issues/3234 add parallelLabels for blueprint/pipeline

Posted by GitBox <gi...@apache.org>.
likyh commented on code in PR #3764:
URL: https://github.com/apache/incubator-devlake/pull/3764#discussion_r1030249762


##########
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:
   fixed



-- 
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: commits-unsubscribe@devlake.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-devlake] klesh merged pull request #3764: Issues/3234 add parallelLabels for blueprint/pipeline

Posted by GitBox <gi...@apache.org>.
klesh merged PR #3764:
URL: https://github.com/apache/incubator-devlake/pull/3764


-- 
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: commits-unsubscribe@devlake.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org