From c51b3b368141eeff466a94c9eadb1848f52822d5 Mon Sep 17 00:00:00 2001 From: Richard LT Date: Tue, 23 Jun 2020 12:12:07 +0200 Subject: [PATCH] fix(api): resync workflow run status when stopping a job (#5275) --- engine/api/workflow/resync_workflow.go | 3 ++- engine/api/workflow_run.go | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/engine/api/workflow/resync_workflow.go b/engine/api/workflow/resync_workflow.go index f80bc728ed..fcdbd35672 100644 --- a/engine/api/workflow/resync_workflow.go +++ b/engine/api/workflow/resync_workflow.go @@ -70,10 +70,11 @@ func ResyncWorkflowRunStatus(ctx context.Context, db gorp.SqlExecutor, wr *sdk.W newStatus = getRunStatus(counterStatus) } + log.Debug("ResyncWorkflowRunStatus> %s/%s %+v", newStatus, wr.Status, counterStatus) + if newStatus != wr.Status { wr.Status = newStatus report.Add(ctx, *wr) - return report, UpdateWorkflowRunStatus(db, wr) } diff --git a/engine/api/workflow_run.go b/engine/api/workflow_run.go index 1fb6efb29e..d134a9a2c3 100644 --- a/engine/api/workflow_run.go +++ b/engine/api/workflow_run.go @@ -697,12 +697,20 @@ func (api *API) stopWorkflowNodeRunHandler() service.Handler { return sdk.WrapError(err, "unable to stop workflow node run") } + // Reload workflow run then resync its status tx, err := api.mustDB().Begin() if err != nil { return sdk.WithStack(err) } defer tx.Rollback() // nolint + workflowRun, err = workflow.LoadRun(ctx, tx, p.Key, workflowName, workflowRunNumber, workflow.LoadRunOptions{ + WithDeleted: true, + }) + if err != nil { + return sdk.WrapError(err, "unable to load workflow run with number %d for workflow %s", workflowRunNumber, workflowName) + } + r1, err := workflow.ResyncWorkflowRunStatus(ctx, tx, workflowRun) report.Merge(ctx, r1) if err != nil {