Skip to content

Commit b633262

Browse files
geroplroboquat
authored andcommitted
[server] Restart PVC workspace from latest valid backup
1 parent f89cbd4 commit b633262

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

Diff for: components/server/src/workspace/workspace-starter.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -337,14 +337,14 @@ export class WorkspaceStarter {
337337

338338
// check if there has been an instance before, i.e. if this is a restart
339339
const pastInstances = await this.workspaceDb.trace({ span }).findInstances(workspace.id);
340-
const hasValidBackup = pastInstances.some(
341-
(i) => !!i.status && !!i.status.conditions && !i.status.conditions.failed,
342-
);
343340
let lastValidWorkspaceInstance: WorkspaceInstance | undefined;
344-
if (hasValidBackup) {
345-
lastValidWorkspaceInstance = pastInstances.reduce((previousValue, currentValue) =>
346-
currentValue.creationTime > previousValue.creationTime ? currentValue : previousValue,
347-
);
341+
// Sorted from latest to oldest
342+
for (const i of pastInstances.sort((a, b) => (a.creationTime > b.creationTime ? -1 : 1))) {
343+
// We're trying to figure out whether there was a successful backup or not, and if yes for which instance
344+
if (!!i.status.conditions && !i.status.conditions.failed) {
345+
lastValidWorkspaceInstance = i;
346+
break;
347+
}
348348
}
349349

350350
const ideConfig = await this.ideService.getIDEConfig();

0 commit comments

Comments
 (0)