@@ -10,12 +10,14 @@ import (
10
10
"github.com/rockbears/log"
11
11
"go.opencensus.io/stats"
12
12
13
+ "github.com/ovh/cds/engine/api/database/gorpmapping"
13
14
"github.com/ovh/cds/engine/api/integration"
14
15
"github.com/ovh/cds/engine/api/objectstore"
15
16
"github.com/ovh/cds/engine/api/project"
16
17
"github.com/ovh/cds/engine/api/services"
17
18
"github.com/ovh/cds/engine/api/workflow"
18
19
"github.com/ovh/cds/engine/cache"
20
+ "github.com/ovh/cds/engine/featureflipping"
19
21
"github.com/ovh/cds/sdk"
20
22
"github.com/ovh/cds/sdk/telemetry"
21
23
)
@@ -55,6 +57,11 @@ func WorkflowRuns(ctx context.Context, DBFunc func() *gorp.DbMap, sharedStorage
55
57
return
56
58
}
57
59
case <- tickPurge .C :
60
+ // Check all workflows to mark runs that should be deleted
61
+ if err := MarkWorkflowRuns (ctx , DBFunc (), workflowRunsMarkToDelete ); err != nil {
62
+ log .Warn (ctx , "purge> Error: %v" , err )
63
+ }
64
+
58
65
log .Debug (ctx , "purge> Deleting all workflow run marked to delete..." )
59
66
if err := deleteWorkflowRunsHistory (ctx , DBFunc (), sharedStorage , workflowRunsDeleted ); err != nil {
60
67
log .Warn (ctx , "purge> Error on deleteWorkflowRunsHistory : %v" , err )
@@ -84,6 +91,41 @@ func Workflow(ctx context.Context, store cache.Store, DBFunc func() *gorp.DbMap,
84
91
}
85
92
}
86
93
94
+ // MarkWorkflowRuns Deprecated: old method to mark runs to delete
95
+ func MarkWorkflowRuns (ctx context.Context , db * gorp.DbMap , workflowRunsMarkToDelete * stats.Int64Measure ) error {
96
+ dao := new (workflow.WorkflowDAO )
97
+ dao .Filters .DisableFilterDeletedWorkflow = false
98
+ wfs , err := dao .LoadAll (ctx , db )
99
+ if err != nil {
100
+ return err
101
+ }
102
+ for _ , wf := range wfs {
103
+ _ , enabled := featureflipping .IsEnabled (ctx , gorpmapping .Mapper , db , sdk .FeaturePurgeName , map [string ]string {"project_key" : wf .ProjectKey })
104
+ if enabled {
105
+ continue
106
+ }
107
+ tx , err := db .Begin ()
108
+ if err != nil {
109
+ log .Error (ctx , "workflow.PurgeWorkflowRuns> error %v" , err )
110
+ tx .Rollback () // nolint
111
+ continue
112
+ }
113
+ if err := workflow .PurgeWorkflowRun (ctx , tx , wf ); err != nil {
114
+ log .Error (ctx , "workflow.PurgeWorkflowRuns> error %v" , err )
115
+ tx .Rollback () // nolint
116
+ continue
117
+ }
118
+ if err := tx .Commit (); err != nil {
119
+ log .Error (ctx , "workflow.PurgeWorkflowRuns> unable to commit transaction: %v" , err )
120
+ _ = tx .Rollback ()
121
+ continue
122
+ }
123
+ }
124
+
125
+ workflow .CountWorkflowRunsMarkToDelete (ctx , db , workflowRunsMarkToDelete )
126
+ return nil
127
+ }
128
+
87
129
// workflows purges all marked workflows
88
130
func workflows (ctx context.Context , db * gorp.DbMap , store cache.Store , workflowRunsMarkToDelete * stats.Int64Measure ) error {
89
131
query := "SELECT id, project_id FROM workflow WHERE to_delete = true ORDER BY id ASC"
0 commit comments