Skip to content

Commit c9d2513

Browse files
bnjjjsguiheux
authored andcommitted
fix(api): fix stop workflow purge (#3279)
1 parent ff2de67 commit c9d2513

File tree

6 files changed

+43
-16
lines changed

6 files changed

+43
-16
lines changed

engine/api/workflow/dao_run.go

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,10 @@ func PurgeWorkflowRun(db gorp.SqlExecutor, wf sdk.Workflow) error {
690690
idsToUpdate = idsToUpdate[:100]
691691
}
692692

693+
if len(idsToUpdate) == 0 {
694+
return nil
695+
}
696+
693697
queryUpdate := `UPDATE workflow_run SET to_delete = true WHERE workflow_run.id = ANY(string_to_array($1, ',')::bigint[])`
694698
if _, err := db.Exec(queryUpdate, strings.Join(idsToUpdate, ",")); err != nil {
695699
log.Warning("PurgeWorkflowRun> Unable to update workflow run for purge for workflow id %d and history length %d : %s", wf.ID, wf.HistoryLength, err)
@@ -769,6 +773,10 @@ func stopRunsBlocked(db *gorp.DbMap) error {
769773
return sdk.WrapError(err, "stopRunsBlocked>")
770774
}
771775

776+
if len(ids) == 0 {
777+
return nil
778+
}
779+
772780
tx, errTx := db.Begin()
773781
if errTx != nil {
774782
return sdk.WrapError(errTx, "stopRunsBlocked>")
@@ -780,26 +788,34 @@ func stopRunsBlocked(db *gorp.DbMap) error {
780788
wfIds[i] = fmt.Sprintf("%d", ids[i].ID)
781789
}
782790
wfIdsJoined := strings.Join(wfIds, ",")
783-
queryUpdateWf := `UPDATE workflow_run SET status = $1 WHERE id = ANY(string_to_array($2, ',')::bigint[])`
784-
if _, err := tx.Exec(queryUpdateWf, sdk.StatusStopped.String(), wfIdsJoined); err != nil {
785-
return sdk.WrapError(err, "stopRunsBlocked> Unable to stop workflow run history")
786-
}
787791
args := []interface{}{sdk.StatusStopped.String(), wfIdsJoined, sdk.StatusBuilding.String(), sdk.StatusChecking.String(), sdk.StatusWaiting.String()}
792+
queryUpdateNodeJobRun := `DELETE FROM workflow_node_run_job
793+
WHERE (workflow_node_run_job.workflow_node_run_id IN (
794+
SELECT workflow_node_run.id
795+
FROM workflow_node_run
796+
WHERE (
797+
workflow_node_run.workflow_run_id = ANY(string_to_array($2, ',')::bigint[])
798+
AND (status = $3 OR status = $4 OR status = $5)
799+
)
800+
OR
801+
(workflow_node_run.status = $6 OR workflow_node_run.status = $1 OR workflow_node_run.status = $7)
802+
)
803+
)`
804+
argsNodeJobRun := append(args, sdk.StatusFail.String(), sdk.StatusSuccess.String())
805+
if _, err := tx.Exec(queryUpdateNodeJobRun, argsNodeJobRun...); err != nil {
806+
return sdk.WrapError(err, "stopRunsBlocked> Unable to stop workflow node job run history")
807+
}
808+
788809
queryUpdateNodeRun := `UPDATE workflow_node_run SET status = $1, done = now()
789810
WHERE workflow_run_id = ANY(string_to_array($2, ',')::bigint[])
790811
AND (status = $3 OR status = $4 OR status = $5)`
791812
if _, err := tx.Exec(queryUpdateNodeRun, args...); err != nil {
792813
return sdk.WrapError(err, "stopRunsBlocked> Unable to stop workflow node run history")
793814
}
794-
queryUpdateNodeJobRun := `UPDATE workflow_node_run_job SET status = $1, done = now()
795-
WHERE workflow_node_run_job.workflow_node_run_id IN (
796-
SELECT workflow_node_run.id
797-
FROM workflow_node_run
798-
WHERE workflow_node_run.workflow_run_id = ANY(string_to_array($2, ',')::bigint[])
799-
AND (status = $3 OR status = $4 OR status = $5)
800-
)`
801-
if _, err := tx.Exec(queryUpdateNodeJobRun, args...); err != nil {
802-
return sdk.WrapError(err, "stopRunsBlocked> Unable to stop workflow node job run history")
815+
816+
queryUpdateWf := `UPDATE workflow_run SET status = $1 WHERE id = ANY(string_to_array($2, ',')::bigint[])`
817+
if _, err := tx.Exec(queryUpdateWf, sdk.StatusStopped.String(), wfIdsJoined); err != nil {
818+
return sdk.WrapError(err, "stopRunsBlocked> Unable to stop workflow run history")
803819
}
804820

805821
resp := []struct {

ui/src/app/shared/action/step/form/step.form.component.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export class ActionStepFormComponent implements OnInit {
3131
this.step.optional = optional;
3232
this.step.always_executed = always_executed;
3333
this.step.enabled = true;
34+
this.step.step_name = this.step.name;
3435
this.showAddStep = false;
3536
this.create.emit(new StepEvent('add', this.step));
3637
}

ui/src/app/shared/action/step/step.component.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@ export class ActionStepComponent {
1616
@Input('step')
1717
set step(step: Action) {
1818
this._step = step;
19-
if (step && step.parameters) {
19+
if (step) {
20+
this._step.step_name = this._step.step_name || this._step.name;
21+
if (step.parameters) {
2022
this.withAdvanced = step.parameters.some((parameter) => parameter.advanced);
21-
this._step.step_name = this._step.step_name || this._step.name;
23+
}
2224
}
2325
}
2426
get step(): Action {

ui/src/app/shared/action/step/step.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
</span>
2828
<i class="stepname" *ngIf="!edit || editStepName">({{step.name}})</i>
2929
</span>
30-
<span class="textOrange" *ngIf="action.deprecated">
30+
<span class="textOrange" *ngIf="step.deprecated">
3131
<i class="warning orange sign icon"></i>{{'common_deprecated' | translate}}
3232
</span>
3333
</div>

ui/src/app/views/workflow/run/node/pipeline/step/step.log.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
</div>
66
<div class="title" [title]="startExec ? ('step_title_duration' | translate:{start: startExec, end: doneExec}) : ''">
77
<span *ngIf="!step.step_name">{{step.name}}</span><span *ngIf="step.step_name">{{step.step_name}}</span> {{duration}}
8+
<i class="textOrange" *ngIf="step.deprecated">
9+
<i class="warning orange sign icon"></i>{{'common_deprecated' | translate}}
10+
</i>
811
</div>
912
<div class="right floated flags" *ngIf="step.optional">
1013
<i class="warning sign icon orange stepWarn" *ngIf="currentStatus === pipelineBuildStatusEnum.FAIL && step.optional"></i>{{ 'action_optional' | translate }}

ui/src/app/views/workflow/run/node/pipeline/step/step.log.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ $squareSize: 32px;
3838
}
3939
}
4040

41+
.textOrange {
42+
color: $cds_color_orange;
43+
font-size: 12px;
44+
}
45+
4146
.logs {
4247
background-color: #222;
4348
color: white;

0 commit comments

Comments
 (0)