Skip to content

Commit

Permalink
fix(api): keep spawnInfos on stop (#3799)
Browse files Browse the repository at this point in the history
  • Loading branch information
yesnault authored and sguiheux committed Jan 3, 2019
1 parent 2c24af7 commit dc56e1b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
2 changes: 1 addition & 1 deletion engine/api/workflow/dao_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -861,7 +861,7 @@ func stopRunsBlocked(db *gorp.DbMap) error {
return sdk.WrapError(err, "cannot unmarshal stages")
}

stopWorkflowNodeRunStages(&nr)
stopWorkflowNodeRunStages(db, &nr)
if !sdk.StatusIsTerminated(resp[i].Status) {
nr.Status = sdk.StatusStopped.String()
nr.Done = now
Expand Down
22 changes: 19 additions & 3 deletions engine/api/workflow/execute_node_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -685,14 +685,23 @@ func stopWorkflowNodePipeline(ctx context.Context, dbFunc func() *gorp.DbMap, st
}
wg.Wait()

tx, errTx := dbFunc().Begin()
if errTx != nil {
return nil, sdk.WrapError(errTx, "stopWorkflowNodePipeline> Unable to create transaction")
}
defer tx.Rollback() //nolint

// Update stages from node run
stopWorkflowNodeRunStages(nodeRun)
stopWorkflowNodeRunStages(tx, nodeRun)

nodeRun.Status = sdk.StatusStopped.String()
nodeRun.Done = time.Now()
if errU := UpdateNodeRun(dbFunc(), nodeRun); errU != nil {
if errU := UpdateNodeRun(tx, nodeRun); errU != nil {
return report, sdk.WrapError(errU, "stopWorkflowNodePipeline> Cannot update node run")
}
if err := tx.Commit(); err != nil {
return nil, sdk.WrapError(err, "stopWorkflowNodePipeline> Cannot commit transaction")
}
return report, nil
}

Expand Down Expand Up @@ -754,12 +763,19 @@ func StopWorkflowNodeRun(ctx context.Context, dbFunc func() *gorp.DbMap, store c
}

// stopWorkflowNodeRunStages mark to stop all stages and step status in struct
func stopWorkflowNodeRunStages(nodeRun *sdk.WorkflowNodeRun) {
func stopWorkflowNodeRunStages(db gorp.SqlExecutor, nodeRun *sdk.WorkflowNodeRun) {
// Update stages from node run
for iS := range nodeRun.Stages {
stag := &nodeRun.Stages[iS]
for iR := range stag.RunJobs {
runj := &stag.RunJobs[iR]
spawnInfos, err := LoadNodeRunJobInfo(db, runj.ID)
if err != nil {
log.Warning("unable to load spawn infos for runj ID: %d", runj.ID)
} else {
runj.SpawnInfos = spawnInfos
}

if !sdk.StatusIsTerminated(runj.Status) {
runj.Status = sdk.StatusStopped.String()
runj.Done = time.Now()
Expand Down

0 comments on commit dc56e1b

Please sign in to comment.