8000 fix(api): delete one workflow run per request · ovh/cds@28e2490 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Commit 28e2490

Browse files
committed
fix(api): delete one workflow run per request
1 parent 6e1ba6e commit 28e2490

File tree

2 files changed

+27
-9
lines changed

2 files changed

+27
-9
lines changed

engine/api/purge/purge.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -145,18 +145,19 @@ func workflows(ctx context.Context, db *gorp.DbMap, store cache.Store, workflowR
145145

146146
// deleteWorkflowRunsHistory is useful to delete all the workflow run marked with to delete flag in db
147147
func deleteWorkflowRunsHistory(ctx context.Context, db gorp.SqlExecutor, workflowRunsDeleted *stats.Int64Measure) error {
148-
query := `DELETE FROM workflow_run WHERE workflow_run.id IN (SELECT id FROM workflow_run WHERE to_delete = true LIMIT 30)`
149-
150-
res, err := db.Exec(query)
151-
if err != nil {
152-
log.Warning("deleteWorkflowRunsHistory> Unable to delete workflow history %s", err)
148+
var ids []int64
149+
if _, err := db.Select(&ids, "SELECT id FROM workflow_run WHERE to_delete = true ORDER BY id ASC LIMIT 1000"); err != nil {
153150
return err
154151
}
155152

156-
n, _ := res.RowsAffected()
157-
if workflowRunsDeleted != nil {
158-
observability.Record(ctx, workflowRunsDeleted, n)
153+
for _, id := range ids {
154+
if _, err := db.Exec("DELETE FROM workflow_run WHERE workflow_run.id = $1", id); err != nil {
155+
log.Error("deleteWorkflowRunsHistory> unable to delete workflow run %d: %v", id, err)
156+
continue
157+
}
158+
if workflowRunsDeleted != nil {
159+
observability.Record(ctx, workflowRunsDeleted, 1)
160+
}
159161
}
160-
161162
return nil
162163
}

engine/api/purge/purge_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package purge
2+
3+
import (
4+
"context"
5+
"testing"
6+
7+
"github.com/ovh/cds/engine/api/bootstrap"
8+
"github.com/ovh/cds/engine/api/test"
9+
)
10+
11+
func Test_deleteWorkflowRunsHistory(t *testing.T) {
12+
db, _, end := test.SetupPG(t, bootstrap.InitiliazeDB)
13+
defer end()
14+
15+
err := deleteWorkflowRunsHistory(context.Background(), db, nil)
16+
test.NoError(t, err)
17+
}

0 commit comments

Comments
 (0)
0