You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@devlake.apache.org by ab...@apache.org on 2022/12/21 11:39:33 UTC

[incubator-devlake] branch main updated: refactor: add error_name to _devlake_pipelines and _devlake_tasks (#4008)

This is an automated email from the ASF dual-hosted git repository.

abeizn pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git


The following commit(s) were added to refs/heads/main by this push:
     new d66e5998a refactor: add error_name to _devlake_pipelines and _devlake_tasks (#4008)
d66e5998a is described below

commit d66e5998a7d458861d61818a693a28d01402e9cf
Author: mindlesscloud <li...@merico.dev>
AuthorDate: Wed Dec 21 19:39:29 2022 +0800

    refactor: add error_name to _devlake_pipelines and _devlake_tasks (#4008)
---
 models/migrationscripts/20221221_add_error_name.go | 54 ++++++++++++++++++++++
 models/migrationscripts/register.go                |  1 +
 models/pipeline.go                                 |  2 +
 models/task.go                                     |  1 +
 runner/run_task.go                                 |  1 +
 services/pipeline_helper.go                        |  1 +
 services/pipeline_runner.go                        |  1 +
 7 files changed, 61 insertions(+)

diff --git a/models/migrationscripts/20221221_add_error_name.go b/models/migrationscripts/20221221_add_error_name.go
new file mode 100644
index 000000000..e3a1c8268
--- /dev/null
+++ b/models/migrationscripts/20221221_add_error_name.go
@@ -0,0 +1,54 @@
+/*
+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/helpers/migrationhelper"
+	"github.com/apache/incubator-devlake/plugins/core"
+)
+
+type pipeline20221221 struct {
+	ErrorName string
+}
+
+func (pipeline20221221) TableName() string {
+	return "_devlake_pipelines"
+}
+
+type task20221221 struct {
+	ErrorName string
+}
+
+func (task20221221) TableName() string {
+	return "_devlake_tasks"
+}
+
+type addErrorName struct{}
+
+func (script *addErrorName) Up(basicRes core.BasicRes) errors.Error {
+	return migrationhelper.AutoMigrateTables(basicRes, &pipeline20221221{}, &task20221221{})
+}
+
+func (*addErrorName) Version() uint64 {
+	return 20221221150548
+}
+
+func (*addErrorName) Name() string {
+	return "add error_name to _devlake_tasks and _devlake_pipelines"
+}
diff --git a/models/migrationscripts/register.go b/models/migrationscripts/register.go
index aa5da7604..0db6254ff 100644
--- a/models/migrationscripts/register.go
+++ b/models/migrationscripts/register.go
@@ -65,5 +65,6 @@ func All() []core.MigrationScript {
 		new(addEnableToProjectMetric),
 		new(addCollectorMeta20221125),
 		new(addOriginalProject),
+		new(addErrorName),
 	}
 }
diff --git a/models/pipeline.go b/models/pipeline.go
index 97fba77e4..0bd428e82 100644
--- a/models/pipeline.go
+++ b/models/pipeline.go
@@ -37,6 +37,7 @@ type Pipeline struct {
 	FinishedAt    *time.Time     `json:"finishedAt" gorm:"index"`
 	Status        string         `json:"status"`
 	Message       string         `json:"message"`
+	ErrorName     string         `json:"errorName"`
 	SpentSeconds  int            `json:"spentSeconds"`
 	Stage         int            `json:"stage"`
 	Labels        []string       `json:"labels"`
@@ -64,6 +65,7 @@ type DbPipeline struct {
 	FinishedAt    *time.Time `json:"finishedAt" gorm:"index"`
 	Status        string     `json:"status"`
 	Message       string     `json:"message"`
+	ErrorName     string     `json:"errorName"`
 	SpentSeconds  int        `json:"spentSeconds"`
 	Stage         int        `json:"stage"`
 	SkipOnFail    bool       `json:"skipOnFail"`
diff --git a/models/task.go b/models/task.go
index 7f09c3437..9ad823447 100644
--- a/models/task.go
+++ b/models/task.go
@@ -54,6 +54,7 @@ type Task struct {
 	Options        datatypes.JSON      `json:"options"`
 	Status         string              `json:"status"`
 	Message        string              `json:"message"`
+	ErrorName      string              `json:"errorName"`
 	Progress       float32             `json:"progress"`
 	ProgressDetail *TaskProgressDetail `json:"progressDetail" gorm:"-"`
 
diff --git a/runner/run_task.go b/runner/run_task.go
index 768368958..ef9ccce36 100644
--- a/runner/run_task.go
+++ b/runner/run_task.go
@@ -86,6 +86,7 @@ func RunTask(
 			dbe := db.UpdateColumns(task, []dal.DalSet{
 				{ColumnName: "status", Value: models.TASK_FAILED},
 				{ColumnName: "message", Value: lakeErr.Error()},
+				{ColumnName: "error_name", Value: lakeErr.Messages().Format()},
 				{ColumnName: "finished_at", Value: finishedAt},
 				{ColumnName: "spent_seconds", Value: spentSeconds},
 				{ColumnName: "failed_sub_task", Value: subTaskName},
diff --git a/services/pipeline_helper.go b/services/pipeline_helper.go
index 4aea9279e..7a3f80eac 100644
--- a/services/pipeline_helper.go
+++ b/services/pipeline_helper.go
@@ -208,6 +208,7 @@ func parsePipeline(dbPipeline *models.DbPipeline) *models.Pipeline {
 		FinishedAt:    dbPipeline.FinishedAt,
 		Status:        dbPipeline.Status,
 		Message:       dbPipeline.Message,
+		ErrorName:     dbPipeline.ErrorName,
 		SpentSeconds:  dbPipeline.SpentSeconds,
 		Stage:         dbPipeline.Stage,
 		SkipOnFail:    dbPipeline.SkipOnFail,
diff --git a/services/pipeline_runner.go b/services/pipeline_runner.go
index 4347bdcb1..441dd47ab 100644
--- a/services/pipeline_runner.go
+++ b/services/pipeline_runner.go
@@ -128,6 +128,7 @@ func runPipeline(pipelineId uint64) errors.Error {
 	if err != nil {
 		dbPipeline.Status = models.TASK_FAILED
 		dbPipeline.Message = err.Error()
+		dbPipeline.ErrorName = err.Messages().Format()
 	} else {
 		dbPipeline.Status = models.TASK_COMPLETED
 		dbPipeline.Message = ""