Skip to content

Commit

Permalink
fix(api): do not migrate worklow run on status pending (#4008)
Browse files Browse the repository at this point in the history
  • Loading branch information
sguiheux authored Mar 11, 2019
1 parent bdade36 commit 92c3bb4
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 25 deletions.
38 changes: 19 additions & 19 deletions cli/cdsctl/workflow_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,27 +155,27 @@ func workflowStatusRunWithoutTrack(v cli.Values) (interface{}, error) {

var payload []string
var payloadString interface{}
if v, ok := run.WorkflowNodeRuns[run.Workflow.WorkflowData.Node.ID]; ok {
if len(v) > 0 {
payloadString = v[0].Payload
if len(run.WorkflowNodeRuns) > 0 {
if v, ok := run.WorkflowNodeRuns[run.Workflow.WorkflowData.Node.ID]; ok {
if len(v) > 0 {
payloadString = v[0].Payload
}
}
e := dump.NewDefaultEncoder()
e.Formatters = []dump.KeyFormatterFunc{dump.WithDefaultLowerCaseFormatter()}
e.ExtraFields.DetailedMap = false
e.ExtraFields.DetailedStruct = false
e.ExtraFields.Len = false
e.ExtraFields.Type = false
pl, errm1 := e.ToStringMap(payloadString)
if errm1 != nil {
return nil, errm1
}
for k, kv := range pl {
payload = append(payload, fmt.Sprintf("%s:%s", k, kv))
}
payload = append(payload)
}

e := dump.NewDefaultEncoder()
e.Formatters = []dump.KeyFormatterFunc{dump.WithDefaultLowerCaseFormatter()}
e.ExtraFields.DetailedMap = false
e.ExtraFields.DetailedStruct = false
e.ExtraFields.Len = false
e.ExtraFields.Type = false
pl, errm1 := e.ToStringMap(payloadString)
if errm1 != nil {
return nil, errm1
}
for k, kv := range pl {
payload = append(payload, fmt.Sprintf("%s:%s", k, kv))
}
payload = append(payload)

wt := &wtags{*run, strings.Join(payload, " "), strings.Join(tags, " ")}
return *wt, nil
}
2 changes: 1 addition & 1 deletion engine/api/workflow/dao_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ func loadRunTags(db gorp.SqlExecutor, run *sdk.WorkflowRun) error {
}

func MigrateWorkflowRun(ctx context.Context, db gorp.SqlExecutor, run *sdk.WorkflowRun) error {
if run != nil && run.Workflow.WorkflowData == nil {
if run != nil && run.Workflow.WorkflowData == nil && run.Status != sdk.StatusPending.String() {
data := run.Workflow.Migrate(true)
run.Workflow.WorkflowData = &data

Expand Down
5 changes: 3 additions & 2 deletions engine/api/workflow_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -848,9 +848,10 @@ func (api *API) postWorkflowRunHandler() service.Handler {
}
}

defer func() {
// Purge workflow run
sdk.GoRoutine(ctx, fmt.Sprintf("api.initWorkflowRun-%d", lastRun.ID), func(ctx context.Context) {
api.initWorkflowRun(ctx, api.mustDB(), api.Cache, p, wf, lastRun, opts, u)
}()
}, api.PanicDump())

return service.WriteJSON(w, lastRun, http.StatusAccepted)
}
Expand Down
25 changes: 25 additions & 0 deletions engine/api/workflow_run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -921,6 +921,31 @@ func Test_resyncWorkflowRunHandler(t *testing.T) {
test.NoError(t, json.Unmarshal(rec.Body.Bytes(), wr))
assert.Equal(t, int64(1), wr.Number)

cpt := 0
for {
varsGet := map[string]string{
"key": proj.Key,
"permWorkflowName": w1.Name,
"number": "1",
}
uriGet := router.GetRoute("GET", api.getWorkflowRunHandler, varsGet)
reqGet := assets.NewAuthentifiedRequest(t, u, pass, "GET", uriGet, nil)
recGet := httptest.NewRecorder()
router.Mux.ServeHTTP(recGet, reqGet)

var wrGet sdk.WorkflowRun
assert.NoError(t, json.Unmarshal(recGet.Body.Bytes(), &wrGet))

if wrGet.Status != sdk.StatusPending.String() {
assert.Equal(t, sdk.StatusBuilding.String(), wrGet.Status)
break
}
cpt++
if cpt > 10 {
break
}
}

pip.Stages[0].Name = "New awesome stage"
errS := pipeline.UpdateStage(db, &pip.Stages[0])
test.NoError(t, errS)
Expand Down
3 changes: 2 additions & 1 deletion tests/sc_workflow_create_run_join.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ testcases:
- result.code ShouldEqual 0
- "result.systemout ShouldContainSubstring Workflow ITSCWRKFLW3-WORKFLOW #2 has been launched"
- script: "{{.cds.build.cdsctl}} workflow status ITSCWRKFLW3 ITSCWRKFLW3-WORKFLOW 2 --format json"
retry: 10
delay: 3
assertions:
- result.code ShouldEqual 0
- result.systemoutjson.status ShouldEqual Building
- result.systemoutjson.tags ShouldContainSubstring master
- result.systemoutjson.num ShouldContainSubstring 2
2 changes: 2 additions & 0 deletions tests/sc_workflow_payload_merge_run.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ testcases:
- name: check workflow
steps:
- script: "{{.cds.build.cdsctl}} workflow status ITSCWRKFLW2 ITSCWRKFLW2-WORKFLOW 1 --format json"
retry: 10
delay: 3
assertions:
- result.code ShouldEqual 0
- result.systemoutjson.last_execution ShouldNotBeEmpty
Expand Down
2 changes: 2 additions & 0 deletions tests/sc_workflow_run_simple.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ testcases:
- name: check workflow
steps:
- script: {{.cds.build.cdsctl}} workflow status ITSCWRKFLW2 ITSCWRKFLW2-WORKFLOW 1 --format json
retry: 10
delay: 3
assertions:
- result.code ShouldEqual 0
- result.systemoutjson.last_execution ShouldNotBeEmpty
Expand Down
2 changes: 2 additions & 0 deletions tests/sc_workflow_stop_simple.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ testcases:
- name: check workflow
steps:
- script: {{.cds.build.cdsctl}} workflow status ITSCWRKFLW2 ITSCWRKFLW2-WORKFLOW 1 --format json
retry: 10
delay: 3
assertions:
- result.code ShouldEqual 0
- result.systemoutjson.last_execution ShouldNotBeEmpty
Expand Down
4 changes: 4 additions & 0 deletions tests/sc_workflow_update_run.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ testcases:
- name: check workflow
steps:
- script: {{.cds.build.cdsctl}} workflow status ITSCWRKFLW2 ITSCWRKFLW2-WORKFLOW 1 --format json
retry: 10
delay: 3
assertions:
- result.code ShouldEqual 0
- result.systemoutjson.last_execution ShouldNotBeEmpty
Expand All @@ -55,6 +57,8 @@ testcases:
- name: check workflow run 2
steps:
- script: {{.cds.build.cdsctl}} workflow status ITSCWRKFLW2 ITSCWRKFLW2-WORKFLOW 2 --format json
retry: 10
delay: 3
assertions:
- result.code ShouldEqual 0
- result.systemoutjson.last_execution ShouldNotBeEmpty
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<div class="number">
<span class="hash">#</span>
<span class="count" [class.success]="r.status === pipelineStatusEnum.SUCCESS"
[class.waiting]="r.status === pipelineStatusEnum.BUILDING || r.status === pipelineStatusEnum.WAITING"
[class.waiting]="r.status === pipelineStatusEnum.BUILDING || r.status === pipelineStatusEnum.WAITING || r.status === pipelineStatusEnum.PENDING"
[class.fail]="r.status === pipelineStatusEnum.FAIL || r.status === pipelineStatusEnum.STOPPED"
[class.never]="r.status === pipelineStatusEnum.NEVER_BUILT || r.status === pipelineStatusEnum.SKIPPED || r.status === pipelineStatusEnum.DISABLED">{{r.num}}</span>
</div>
Expand Down
2 changes: 1 addition & 1 deletion ui/src/app/views/account/verify/verify.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class VerifyComponent extends AccountComponent implements OnInit {

signIn() {
let userloginRequest = new UserLoginRequest();
userloginRequest.username = this.userVerified.user;
userloginRequest.username = this.userVerified.user.username;
userloginRequest.password = this.userVerified.password;

this._userService.login(userloginRequest).subscribe(() => {
Expand Down

0 comments on commit 92c3bb4

Please sign in to comment.