@@ -49,16 +49,26 @@ export class WorkspaceGarbageCollector implements Job {
49
49
return ;
50
50
}
51
51
52
- await Promise . all ( [
53
- this . softDeleteOldWorkspaces ( ) . catch ( ( err ) => log . error ( "workspace-gc: error during soft-deletion" , err ) ) ,
54
- this . deleteWorkspaceContentAfterRetentionPeriod ( ) . catch ( ( err ) =>
55
- log . error ( "workspace-gc: error during content deletion" , err ) ,
56
- ) ,
57
- this . purgeWorkspacesAfterPurgeRetentionPeriod ( ) . catch ( ( err ) =>
58
- log . error ( "workspace-gc: error during hard deletion of workspaces" , err ) ,
59
- ) ,
60
- this . deleteOldPrebuilds ( ) . catch ( ( err ) => log . error ( "workspace-gc: error during prebuild deletion" , err ) ) ,
61
- ] ) ;
52
+ try {
53
+ await this . softDeleteOldWorkspaces ( ) ;
54
+ } catch ( error ) {
55
+ log . error ( "workspace-gc: error during garbage collection" , error ) ;
56
+ }
57
+ try {
58
+ await this . deleteWorkspaceContentAfterRetentionPeriod ( ) ;
59
+ } catch ( error ) {
60
+ log . error ( "workspace-gc: error during content deletion" , error ) ;
61
+ }
62
+ try {
63
+ await this . purgeWorkspacesAfterPurgeRetentionPeriod ( ) ;
64
+ } catch ( err ) {
65
+ log . error ( "workspace-gc: error during hard deletion of workspaces" , err ) ;
66
+ }
67
+ try {
68
+ await this . deleteOldPrebuilds ( ) ;
69
+ } catch ( err ) {
70
+ log . error ( "workspace-gc: error during prebuild deletion" , err ) ;
71
+ }
62
72
}
63
73
64
74
/**
@@ -80,16 +90,21 @@ export class WorkspaceGarbageCollector implements Job {
80
90
this . config . workspaceGarbageCollection . chunkLimit ,
81
91
) ;
82
92
const afterSelect = new Date ( ) ;
83
- const deletes = await Promise . all (
84
- workspaces . map ( ( ws ) => this . workspaceService . deleteWorkspace ( SYSTEM_USER , ws . id , "gc" ) ) ,
85
- ) ;
93
+ log . info ( `workspace-gc: about to soft-delete ${ workspaces . length } workspaces` ) ;
94
+ for ( const ws of workspaces ) {
95
+ try {
96
+ await this . workspaceService . deleteWorkspace ( SYSTEM_USER , ws . id , "gc" ) ;
97
+ } catch ( err ) {
98
+ log . error ( { workspaceId : ws . id } , "workspace-gc: error during workspace soft-deletion" , err ) ;
99
+ }
100
+ }
86
101
const afterDelete = new Date ( ) ;
87
102
88
- log . info ( `workspace-gc: successfully soft-deleted ${ deletes . length } workspaces` , {
103
+ log . info ( `workspace-gc: successfully soft-deleted ${ workspaces . length } workspaces` , {
89
104
selectionTimeMs : afterSelect . getTime ( ) - now . getTime ( ) ,
90
105
deletionTimeMs : afterDelete . getTime ( ) - afterSelect . getTime ( ) ,
91
106
} ) ;
92
- span . addTags ( { nrOfCollectedWorkspaces : deletes . length } ) ;
107
+ span . addTags ( { nrOfCollectedWorkspaces : workspaces . length } ) ;
93
108
} catch ( err ) {
94
109
TraceContext . setError ( { span } , err ) ;
95
110
throw err ;
@@ -101,16 +116,29 @@ export class WorkspaceGarbageCollector implements Job {
101
116
private async deleteWorkspaceContentAfterRetentionPeriod ( ) {
102
117
const span = opentracing . globalTracer ( ) . startSpan ( "deleteWorkspaceContentAfterRetentionPeriod" ) ;
103
118
try {
119
+ const now = new Date ( ) ;
104
120
const workspaces = await this . workspaceDB
105
121
. trace ( { span } )
106
122
. findWorkspacesForContentDeletion (
107
123
this . config . workspaceGarbageCollection . contentRetentionPeriodDays ,
108
124
this . config . workspaceGarbageCollection . contentChunkLimit ,
109
125
) ;
110
- const deletes = await Promise . all ( workspaces . map ( ( ws ) => this . garbageCollectWorkspace ( { span } , ws ) ) ) ;
126
+ const afterSelect = new Date ( ) ;
127
+ log . info ( `workspace-gc: about to delete the content of ${ workspaces . length } workspaces` ) ;
128
+ for ( const ws of workspaces ) {
129
+ try {
130
+ await this . garbageCollectWorkspace ( { span } , ws ) ;
131
+ } catch ( err ) {
132
+ log . error ( { workspaceId : ws . id } , "workspace-gc: error during workspace content deletion" , err ) ;
133
+ }
134
+ }
135
+ const afterDelete = new Date ( ) ;
111
136
112
- log . info ( `workspace-gc: successfully deleted the content of ${ deletes . length } workspaces` ) ;
113
- span . addTags ( { nrOfCollectedWorkspaces : deletes . length } ) ;
137
+ log . info ( `workspace-gc: successfully deleted the content of ${ workspaces . length } workspaces` , {
138
+ selectionTimeMs : afterSelect . getTime ( ) - now . getTime ( ) ,
139
+ deletionTimeMs : afterDelete . getTime ( ) - afterSelect . getTime ( ) ,
140
+ } ) ;
141
+ span . addTags ( { nrOfCollectedWorkspaces : workspaces . length } ) ;
114
142
} catch ( err ) {
115
143
TraceContext . setError ( { span } , err ) ;
116
144
throw err ;
@@ -133,22 +161,22 @@ export class WorkspaceGarbageCollector implements Job {
133
161
this . config . workspaceGarbageCollection . purgeChunkLimit ,
134
162
now ,
135
163
) ;
136
- const deletes = await Promise . all (
137
- workspaces . map ( ( ws ) =>
138
- this . workspaceService
139
- . hardDeleteWorkspace ( SYSTEM_USER , ws . id )
140
- . catch ( ( err ) =>
141
- log . error (
142
- { userId : ws . ownerId , workspaceId : ws . id } ,
143
- "failed to hard-delete workspace" ,
144
- err ,
145
- ) ,
146
- ) ,
147
- ) ,
148
- ) ;
149
-
150
- log . info ( `workspace-gc: successfully purged ${ deletes . length } workspaces` ) ;
151
- span . addTags ( { nrOfCollectedWorkspaces : deletes . length } ) ;
164
+ const afterSelect = new Date ( ) ;
165
+ log . info ( `workspace-gc: about to purge ${ workspaces . length } workspaces` ) ;
166
+ for ( const ws of workspaces ) {
167
+ try {
168
+ await this . workspaceService . hardDeleteWorkspace ( SYSTEM_USER , ws . id ) ;
169
+ } catch ( err ) {
170
+ log . error ( { workspaceId : ws . id } , "workspace-gc: failed to purge workspace" , err ) ;
171
+ }
172
+ }
173
+ const afterDelete = new Date ( ) ;
174
+
175
+ log . info ( `workspace-gc: successfully purged ${ workspaces . length } workspaces` , {
176
+ selectionTimeMs : afterSelect . getTime ( ) - now . getTime ( ) ,
177
+ deletionTimeMs : afterDelete . getTime ( ) - afterSelect . getTime ( ) ,
178
+ } ) ;
179
+ span . addTags ( { nrOfCollectedWorkspaces : workspaces . length } ) ;
152
180
} catch ( err ) {
153
181
TraceContext . setError ( { span } , err ) ;
154
182
throw err ;
@@ -160,16 +188,29 @@ export class WorkspaceGarbageCollector implements Job {
160
188
private async deleteOldPrebuilds ( ) {
161
189
const span = opentracing . globalTracer ( ) . startSpan ( "deleteOldPrebuilds" ) ;
162
190
try {
191
+ const now = new Date ( ) ;
163
192
const workspaces = await this . workspaceDB
164
193
. trace ( { span } )
165
194
. findPrebuiltWorkspacesForGC (
166
195
this . config . workspaceGarbageCollection . minAgePrebuildDays ,
167
196
this . config . workspaceGarbageCollection . chunkLimit ,
168
197
) ;
169
- const deletes = await Promise . all ( workspaces . map ( ( ws ) => this . garbageCollectPrebuild ( { span } , ws ) ) ) ;
198
+ const afterSelect = new Date ( ) ;
199
+ log . info ( `workspace-gc: about to delete ${ workspaces . length } prebuilds` ) ;
200
+ for ( const ws of workspaces ) {
201
+ try {
202
+ await this . garbageCollectPrebuild ( { span } , ws ) ;
203
+ } catch ( err ) {
204
+ log . error ( { workspaceId : ws . id } , "workspace-gc: failed to delete prebuild" , err ) ;
205
+ }
206
+ }
207
+ const afterDelete = new Date ( ) ;
170
208
171
- log . info ( `workspace-gc: successfully deleted ${ deletes . length } prebuilds` ) ;
172
- span . addTags ( { nrOfCollectedPrebuilds : deletes . length } ) ;
209
+ log . info ( `workspace-gc: successfully deleted ${ workspaces . length } prebuilds` , {
210
+ selectionTimeMs : afterSelect . getTime ( ) - now . getTime ( ) ,
211
+ deletionTimeMs : afterDelete . getTime ( ) - afterSelect . getTime ( ) ,
212
+ } ) ;
213
+ span . addTags ( { nrOfCollectedPrebuilds : workspaces . length } ) ;
173
214
} catch ( err ) {
174
215
TraceContext . setError ( { span } , err ) ;
175
216
throw err ;
0 commit comments