@@ -34,7 +34,10 @@ export class WorkspaceGarbageCollector {
34
34
dispose : ( ) => { } ,
35
35
} ;
36
36
}
37
- return repeat ( async ( ) => this . garbageCollectWorkspacesIfLeader ( ) , 30 * 60 * 1000 ) ;
37
+ return repeat (
38
+ async ( ) => this . garbageCollectWorkspacesIfLeader ( ) ,
39
+ this . config . workspaceGarbageCollection . intervalSeconds * 1000 ,
40
+ ) ;
38
41
}
39
42
40
43
public async garbageCollectWorkspacesIfLeader ( ) {
@@ -44,6 +47,9 @@ export class WorkspaceGarbageCollector {
44
47
this . deleteWorkspaceContentAfterRetentionPeriod ( ) . catch ( ( err ) =>
45
48
log . error ( "wsgc: error during content deletion" , err ) ,
46
49
) ;
50
+ this . purgeWorkspacesAfterPurgeRetentionPeriod ( ) . catch ( ( err ) =>
51
+ log . error ( "wsgc: error during hard deletion of workspaces" , err ) ,
52
+ ) ;
47
53
this . deleteOldPrebuilds ( ) . catch ( ( err ) => log . error ( "wsgc: error during prebuild deletion" , err ) ) ;
48
54
this . deleteOutdatedVolumeSnapshots ( ) . catch ( ( err ) =>
49
55
log . error ( "wsgc: error during volume snapshot gc deletion" , err ) ,
@@ -105,6 +111,34 @@ export class WorkspaceGarbageCollector {
105
111
}
106
112
}
107
113
114
+ /**
115
+ * This method is meant to purge all traces of a Workspace and it's WorkspaceInstances from the DB
116
+ */
117
+ protected async purgeWorkspacesAfterPurgeRetentionPeriod ( ) {
118
+ const span = opentracing . globalTracer ( ) . startSpan ( "purgeWorkspacesAfterPurgeRetentionPeriod" ) ;
119
+ try {
120
+ const now = new Date ( ) ;
121
+ const workspaces = await this . workspaceDB
122
+ . trace ( { span } )
123
+ . findWorkspacesForPurging (
124
+ this . config . workspaceGarbageCollection . purgeRetentionPeriodDays ,
125
+ this . config . workspaceGarbageCollection . purgeChunkLimit ,
126
+ now ,
127
+ ) ;
128
+ const deletes = await Promise . all (
129
+ workspaces . map ( ( ws ) => this . deletionService . hardDeleteWorkspace ( { span } , ws . id ) ) ,
130
+ ) ;
131
+
132
+ log . info ( `wsgc: successfully purged ${ deletes . length } workspaces` ) ;
133
+ span . addTags ( { nrOfCollectedWorkspaces : deletes . length } ) ;
134
+ } catch ( err ) {
135
+ TraceContext . setError ( { span } , err ) ;
136
+ throw err ;
137
+ } finally {
138
+ span . finish ( ) ;
139
+ }
140
+ }
141
+
108
142
protected async deleteOldPrebuilds ( ) {
109
143
const span = opentracing . globalTracer ( ) . startSpan ( "deleteOldPrebuilds" ) ;
110
144
try {
@@ -128,7 +162,7 @@ export class WorkspaceGarbageCollector {
128
162
}
129
163
}
130
164
131
- // finds volume snapshots that have been superceded by newer volume snapshot and removes them
165
+ // finds volume snapshots that have been superseded by newer volume snapshot and removes them
132
166
protected async deleteOutdatedVolumeSnapshots ( ) {
133
167
const span = opentracing . globalTracer ( ) . startSpan ( "deleteOutdatedVolumeSnapshots" ) ;
134
168
try {
0 commit comments