Skip to content

Commit b50f8b2

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

File tree

2 files changed

+42
-10
lines changed

2 files changed

+42
-10
lines changed

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -886,6 +886,34 @@ 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+
// We need to be forwarded the WorkspaceInstanceUpdates in the frontend, because we do not have
898+
// any other means to reliably learn about the status about image builds, yet.
899+
// Once we have those, we should remove this.
900+
//
901+
const ws = await this.workspaceDb.trace(ctx).findById(workspaceID);
902+
if (!!ws && !!wsi && ws.ownerId !== this.user?.id) {
903+
const resetListener = this.localMessageBroker.listenForWorkspaceInstanceUpdates(
904+
ws.ownerId,
905+
(ctx, instance) => {
906+
if (instance.id === wsi.id) {
907+
this.forwardInstanceUpdateToClient(ctx, instance);
908+
if (instance.status.phase === "stopped") {
909+
resetListener.dispose();
910+
}
911+
}
912+
},
913+
);
914+
this.disposables.push(resetListener);
915+
}
916+
889917
const result = makeResult(wsi.id);
890918

891919
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)