From 2c5b0eb7444abbe3109c48051afafb5f78395987 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Samin?= Date: Wed, 27 May 2020 14:07:19 +0200 Subject: [PATCH] fix(api): don't warn if no previous run was found (#5203) Signed-off-by: francois samin --- engine/api/workflow/dao_node_run.go | 15 ++++++++------- engine/api/workflow_event.go | 6 +++--- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/engine/api/workflow/dao_node_run.go b/engine/api/workflow/dao_node_run.go index a177161db4..8db9040a31 100644 --- a/engine/api/workflow/dao_node_run.go +++ b/engine/api/workflow/dao_node_run.go @@ -692,11 +692,10 @@ func GetNodeRunBuildCommits(ctx context.Context, db gorp.SqlExecutor, store cach } // PreviousNodeRun find previous node run -func PreviousNodeRun(db gorp.SqlExecutor, nr sdk.WorkflowNodeRun, nodeName string, workflowID int64) (sdk.WorkflowNodeRun, error) { - var nodeRun sdk.WorkflowNodeRun +func PreviousNodeRun(db gorp.SqlExecutor, nr sdk.WorkflowNodeRun, nodeName string, workflowID int64) (*sdk.WorkflowNodeRun, error) { // check the first run of a workflow, no need to check previous if nr.Number == 1 && nr.SubNumber == 0 { - return nodeRun, nil + return nil, nil } query := fmt.Sprintf(` SELECT %s FROM workflow_node_run @@ -711,14 +710,16 @@ func PreviousNodeRun(db gorp.SqlExecutor, nr sdk.WorkflowNodeRun, nodeName strin var rr = NodeRun{} if err := db.SelectOne(&rr, query, workflowID, nodeName, nr.VCSBranch, nr.VCSTag, nr.Number, nr.ID); err != nil { - return nodeRun, sdk.WrapError(err, "Cannot load previous run on workflow %d node %s nr.VCSBranch:%s nr.VCSTag:%s nr.Number:%d nr.ID:%d ", workflowID, nodeName, nr.VCSBranch, nr.VCSTag, nr.Number, nr.ID) + if err == sql.ErrNoRows { + return nil, nil + } + return nil, sdk.WrapError(err, "Cannot load previous run on workflow %d node %s nr.VCSBranch:%s nr.VCSTag:%s nr.Number:%d nr.ID:%d ", workflowID, nodeName, nr.VCSBranch, nr.VCSTag, nr.Number, nr.ID) } pNodeRun, errF := fromDBNodeRun(rr, LoadRunOptions{}) if errF != nil { - return nodeRun, sdk.WrapError(errF, "PreviousNodeRun> Cannot read node run") + return nil, sdk.WrapError(errF, "PreviousNodeRun> Cannot read node run") } - nodeRun = *pNodeRun - return nodeRun, nil + return pNodeRun, nil } //PreviousNodeRunVCSInfos returns a struct with BuildNumber, Commit Hash, Branch, Remote, Remote_url diff --git a/engine/api/workflow_event.go b/engine/api/workflow_event.go index 41f6f75417..bb75b58386 100644 --- a/engine/api/workflow_event.go +++ b/engine/api/workflow_event.go @@ -31,9 +31,9 @@ func WorkflowSendEvent(ctx context.Context, db gorp.SqlExecutor, store cache.Sto continue } - var previousNodeRun sdk.WorkflowNodeRun + var previousNodeRun *sdk.WorkflowNodeRun if wnr.SubNumber > 0 { - previousNodeRun = wnr + previousNodeRun = &wnr } else { var errN error previousNodeRun, errN = workflow.PreviousNodeRun(db, wnr, wnr.WorkflowNodeName, wr.WorkflowID) @@ -55,7 +55,7 @@ func WorkflowSendEvent(ctx context.Context, db gorp.SqlExecutor, store cache.Sto log.Warning(ctx, "WorkflowSendEvent> Unable to load workflow for event: %v", err) continue } - eventsNotif := notification.GetUserWorkflowEvents(ctx, db, store, wr.Workflow.ProjectID, wr.Workflow.ProjectKey, workDB.Name, wr.Workflow.Notifications, &previousNodeRun, *nr) + eventsNotif := notification.GetUserWorkflowEvents(ctx, db, store, wr.Workflow.ProjectID, wr.Workflow.ProjectKey, workDB.Name, wr.Workflow.Notifications, previousNodeRun, *nr) event.PublishWorkflowNodeRun(ctx, *nr, wr.Workflow, eventsNotif) e := &workflow.VCSEventMessenger{} if err := e.SendVCSEvent(ctx, db, store, proj, *wr, wnr); err != nil {