Skip to content

Commit 54914fb

Browse files
geroplroboquat
authored andcommitted
[server] Fix tracing and logging when aborting prebuilds on newer push
1 parent 60f4bad commit 54914fb

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

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

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,19 +60,27 @@ export class PrebuildManager {
6060

6161
async abortPrebuildsForBranch(ctx: TraceContext, project: Project, user: User, branch: string): Promise<void> {
6262
const span = TraceContext.startSpan("abortPrebuildsForBranch", ctx);
63-
const prebuilds = await this.workspaceDB
64-
.trace({ span })
65-
.findActivePrebuiltWorkspacesByBranch(project.id, branch);
66-
const results: Promise<any>[] = [];
67-
for (const prebuild of prebuilds) {
68-
for (const instance of prebuild.instances) {
69-
results.push(this.workspaceStarter.stopWorkspaceInstance({ span }, instance.id, instance.region));
63+
try {
64+
const prebuilds = await this.workspaceDB
65+
.trace({ span })
66+
.findActivePrebuiltWorkspacesByBranch(project.id, branch);
67+
const results: Promise<any>[] = [];
68+
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));
75+
}
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));
7079
}
71-
prebuild.prebuild.state = "aborted";
72-
prebuild.prebuild.error = "A newer commit was pushed to the same branch.";
73-
results.push(this.workspaceDB.trace({ span }).storePrebuiltWorkspace(prebuild.prebuild));
80+
await Promise.all(results);
81+
} finally {
82+
span.finish();
7483
}
75-
await Promise.all(results);
7684
}
7785

7886
async startPrebuild(

0 commit comments

Comments
 (0)