Skip to content

Commit

Permalink
fix(api): don't warn if no previous run was found (#5203)
Browse files Browse the repository at this point in the history
Signed-off-by: francois  samin <[email protected]>
  • Loading branch information
fsamin authored May 27, 2020
1 parent ad2757c commit 2c5b0eb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
15 changes: 8 additions & 7 deletions engine/api/workflow/dao_node_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions engine/api/workflow_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 {
Expand Down

0 comments on commit 2c5b0eb

Please sign in to comment.