Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[server] 'abort' prebuilds #12386

Merged
merged 1 commit into from
Sep 6, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 22 additions & 9 deletions components/server/ee/src/prebuilds/prebuild-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -66,16 +68,27 @@ export class PrebuildManager {
.findActivePrebuiltWorkspacesByBranch(project.id, branch);
const results: Promise<any>[] = [];
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,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main change is, to use this new policy which makes ws-manager not care about backups.

),
);
}
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 {
Expand Down