Skip to content

Commit 8ee71c2

Browse files
committed
Listen on instance updates of a running prebuild
even if you are not the workspace owner.
1 parent b59998f commit 8ee71c2

File tree

2 files changed

+38
-10
lines changed

2 files changed

+38
-10
lines changed

components/server/ee/src/workspace/gitpod-server-impl.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -886,6 +886,30 @@ export class GitpodServerEEImpl extends GitpodServerImpl {
886886

887887
return;
888888
}
889+
890+
// (AT) At this point we found a running/building prebuild, which might also include
891+
// image build in current state.
892+
//
893+
// The owner's client connection is automatically registered to listen on instance updates.
894+
// For the remaining client connections which would handle `createWorkspace` and end up here, it
895+
// also would be reasonable to listen on the instance updates of a running prebuild, or image build.
896+
//
897+
const ws = await this.workspaceDb.trace(ctx).findById(workspaceID);
898+
if (!!ws && !!wsi && ws.ownerId !== this.user?.id) {
899+
const resetListener = this.localMessageBroker.listenForWorkspaceInstanceUpdates(
900+
ws.ownerId,
901+
(ctx, instance) => {
902+
if (instance.id === wsi.id) {
903+
this.forwardInstanceUpdateToClient(ctx, instance);
904+
if (instance.status.phase === "stopped") {
905+
resetListener.dispose();
906+
}
907+
}
908+
},
909+
);
910+
this.disposables.push(resetListener);
911+
}
912+
889913
const result = makeResult(wsi.id);
890914

891915
const inSameCluster = wsi.region === this.config.installationShortname;

components/server/src/workspace/gitpod-server-impl.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -276,20 +276,24 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
276276
// to clients who might not otherwise have access to that information.
277277
this.disposables.push(
278278
this.localMessageBroker.listenForWorkspaceInstanceUpdates(this.user.id, (ctx, instance) =>
279-
TraceContext.withSpan(
280-
"forwardInstanceUpdateToClient",
281-
(ctx) => {
282-
traceClientMetadata(ctx, this.clientMetadata);
283-
TraceContext.setJsonRPCMetadata(ctx, "onInstanceUpdate");
284-
285-
this.client?.onInstanceUpdate(this.censorInstance(instance));
286-
},
287-
ctx,
288-
),
279+
this.forwardInstanceUpdateToClient(ctx, instance),
289280
),
290281
);
291282
}
292283

284+
protected forwardInstanceUpdateToClient(ctx: TraceContext, instance: WorkspaceInstance) {
285+
TraceContext.withSpan(
286+
"forwardInstanceUpdateToClient",
287+
(ctx) => {
288+
traceClientMetadata(ctx, this.clientMetadata);
289+
TraceContext.setJsonRPCMetadata(ctx, "onInstanceUpdate");
290+
291+
this.client?.onInstanceUpdate(this.censorInstance(instance));
292+
},
293+
ctx,
294+
);
295+
}
296+
293297
setClient(ctx: TraceContext, client: GitpodApiClient | undefined): void {
294298
throw new Error("Unsupported operation. Use initialize.");
295299
}

0 commit comments

Comments
 (0)