diff --git a/components/server/ee/src/prebuilds/prebuild-manager.ts b/components/server/ee/src/prebuilds/prebuild-manager.ts index f774096d6a6487..d57c43050ca81d 100644 --- a/components/server/ee/src/prebuilds/prebuild-manager.ts +++ b/components/server/ee/src/prebuilds/prebuild-manager.ts @@ -31,6 +31,8 @@ import { secondsBefore } from "@gitpod/gitpod-protocol/lib/util/timeutil"; import { inject, injectable } from "inversify"; import * as opentracing from "opentracing"; +import { StopWorkspacePolicy } from "@gitpod/ws-manager/lib"; +import { error } from "console"; export class WorkspaceRunningError extends Error { constructor(msg: string, public instance: WorkspaceInstance) { @@ -66,16 +68,27 @@ export class PrebuildManager { .findActivePrebuiltWorkspacesByBranch(project.id, branch); const results: Promise[] = []; for (const prebuild of prebuilds) { - for (const instance of prebuild.instances) { - log.info( - { userId: user.id, instanceId: instance.id, workspaceId: instance.workspaceId }, - "Aborting Prebuild workspace because a newer commit was pushed to the same branch.", - ); - results.push(this.workspaceStarter.stopWorkspaceInstance({ span }, instance.id, instance.region)); + try { + for (const instance of prebuild.instances) { + log.info( + { userId: user.id, instanceId: instance.id, workspaceId: instance.workspaceId }, + "Aborting Prebuild workspace because a newer commit was pushed to the same branch.", + ); + results.push( + this.workspaceStarter.stopWorkspaceInstance( + { span }, + instance.id, + instance.region, + StopWorkspacePolicy.ABORT, + ), + ); + } + prebuild.prebuild.state = "aborted"; + prebuild.prebuild.error = "A newer commit was pushed to the same branch."; + results.push(this.workspaceDB.trace({ span }).storePrebuiltWorkspace(prebuild.prebuild)); + } catch (err) { + error("Cannot cancel prebuild", { prebuildID: prebuild.prebuild.id }, err); } - prebuild.prebuild.state = "aborted"; - prebuild.prebuild.error = "A newer commit was pushed to the same branch."; - results.push(this.workspaceDB.trace({ span }).storePrebuiltWorkspace(prebuild.prebuild)); } await Promise.all(results); } finally {