Skip to content

Commit 51c0c6b

Browse files
svenefftingeroboquat
authored andcommitted
[server] 'abort' prebuilds
use the new StopWorkspacePolicy introduced with #12284 to avoid spending resources on backing up discarded prebuilds.
1 parent a03681a commit 51c0c6b

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

components/server/ee/src/prebuilds/prebuild-manager.ts

+22-9
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ import { secondsBefore } from "@gitpod/gitpod-protocol/lib/util/timeutil";
3131

3232
import { inject, injectable } from "inversify";
3333
import * as opentracing from "opentracing";
34+
import { StopWorkspacePolicy } from "@gitpod/ws-manager/lib";
35+
import { error } from "console";
3436

3537
export class WorkspaceRunningError extends Error {
3638
constructor(msg: string, public instance: WorkspaceInstance) {
@@ -66,16 +68,27 @@ export class PrebuildManager {
6668
.findActivePrebuiltWorkspacesByBranch(project.id, branch);
6769
const results: Promise<any>[] = [];
6870
for (const prebuild of prebuilds) {
69-
for (const instance of prebuild.instances) {
70-
log.info(
71-
{ userId: user.id, instanceId: instance.id, workspaceId: instance.workspaceId },
72-
"Aborting Prebuild workspace because a newer commit was pushed to the same branch.",
73-
);
74-
results.push(this.workspaceStarter.stopWorkspaceInstance({ span }, instance.id, instance.region));
71+
try {
72+
for (const instance of prebuild.instances) {
73+
log.info(
74+
{ userId: user.id, instanceId: instance.id, workspaceId: instance.workspaceId },
75+
"Aborting Prebuild workspace because a newer commit was pushed to the same branch.",
76+
);
77+
results.push(
78+
this.workspaceStarter.stopWorkspaceInstance(
79+
{ span },
80+
instance.id,
81+
instance.region,
82+
StopWorkspacePolicy.ABORT,
83+
),
84+
);
85+
}
86+
prebuild.prebuild.state = "aborted";
87+
prebuild.prebuild.error = "A newer commit was pushed to the same branch.";
88+
results.push(this.workspaceDB.trace({ span }).storePrebuiltWorkspace(prebuild.prebuild));
89+
} catch (err) {
90+
error("Cannot cancel prebuild", { prebuildID: prebuild.prebuild.id }, err);
7591
}
76-
prebuild.prebuild.state = "aborted";
77-
prebuild.prebuild.error = "A newer commit was pushed to the same branch.";
78-
results.push(this.workspaceDB.trace({ span }).storePrebuiltWorkspace(prebuild.prebuild));
7992
}
8093
await Promise.all(results);
8194
} finally {

0 commit comments

Comments
 (0)