Skip to content

Commit

Permalink
fix(api): remove only dead job (#4900)
Browse files Browse the repository at this point in the history
  • Loading branch information
sguiheux committed Jan 20, 2020
1 parent 1bf3c5d commit 46d6e99
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
7 changes: 7 additions & 0 deletions engine/api/workflow/dao_node_run_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,13 @@ func DeleteNodeJobRuns(db gorp.SqlExecutor, nodeID int64) error {
return err
}

// DeleteNodeJobRun deletes the given workflow_node_run_job
func DeleteNodeJobRun(db gorp.SqlExecutor, nodeRunJob int64) error {
query := `delete from workflow_node_run_job where id = $1`
_, err := db.Exec(query, nodeRunJob)
return err
}

//UpdateNodeJobRun updates a workflow_node_run_job
func UpdateNodeJobRun(ctx context.Context, db gorp.SqlExecutor, j *sdk.WorkflowNodeJobRun) error {
var end func()
Expand Down
4 changes: 2 additions & 2 deletions engine/api/workflow/heartbeat.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func manageDeadJob(ctx context.Context, DBFunc func() *gorp.DbMap, store cache.S
continue
}

if err := DeleteNodeJobRuns(tx, deadJob.WorkflowNodeRunID); err != nil {
if err := DeleteNodeJobRun(tx, deadJob.ID); err != nil {
log.Error(ctx, "manageDeadJob> Cannot delete node run job %d : %v", deadJob.ID, err)
_ = tx.Rollback()
continue
Expand All @@ -48,7 +48,7 @@ func manageDeadJob(ctx context.Context, DBFunc func() *gorp.DbMap, store cache.S
}
}
} else if sdk.StatusIsTerminated(deadJob.Status) {
if err := DeleteNodeJobRuns(tx, deadJob.WorkflowNodeRunID); err != nil {
if err := DeleteNodeJobRun(tx, deadJob.ID); err != nil {
log.Error(ctx, "manageDeadJob> Cannot delete node run job %d : %v", deadJob.ID, err)
_ = tx.Rollback()
continue
Expand Down
10 changes: 10 additions & 0 deletions tests/fixtures/04SCWorkflowRunWorkerCmd/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ jobs:
- this a a line in the file, with a CDS variable of type password {{.cds.app.password}}
- EOF
- worker check-secret {{.cds.workspace}}/myFile
- script:
- sleep 5
requirements:
- os-architecture: linux/amd64
- job: EXIT
Expand Down Expand Up @@ -62,6 +64,8 @@ jobs:
- EOF
- worker tmpl {{.cds.workspace}}/myFile {{.cds.workspace}}/outputFile
- cat {{.cds.workspace}}/outputFile
- script:
- sleep 5
requirements:
- os-architecture: linux/amd64
- job: UPLOAD
Expand All @@ -82,6 +86,8 @@ jobs:
- set -ex
- worker key install --env proj-ssh-04scworkflowrunworkercmd --file id_rsa
- cat id_rsa
- script:
- sleep 5
requirements:
- os-architecture: linux/amd64
- job: ARTIFACTLIST
Expand All @@ -90,6 +96,7 @@ jobs:
- script:
- set -ex
- worker artifacts
- script:
- sleep 5
requirements:
- os-architecture: linux/amd64
Expand All @@ -100,6 +107,7 @@ jobs:
- set -ex
- worker cache pull latest
- cat fileCache
- script:
- sleep 5
requirements:
- os-architecture: linux/amd64
Expand All @@ -110,6 +118,7 @@ jobs:
- set -ex
- worker download
- cat myFileUploaded
- script:
- sleep 5
requirements:
- os-architecture: linux/amd64
Expand All @@ -119,6 +128,7 @@ jobs:
- script:
- set -ex
- echo "Export value {{.cds.build.foo}}"
- script:
- sleep 5
requirements:
- os-architecture: linux/amd64

0 comments on commit 46d6e99

Please sign in to comment.