From ef17d555a58afcd858c488e93c0a909945ea4755 Mon Sep 17 00:00:00 2001 From: Huiwen Date: Tue, 7 Nov 2023 06:26:04 +0000 Subject: [PATCH] address feedback --- .../src/service/json-rpc-workspace-client.ts | 28 +++++++++++----- .../server/src/api/workspace-service-api.ts | 32 +++++++++++++------ .../server/src/workspace/workspace-service.ts | 3 +- 3 files changed, 44 insertions(+), 19 deletions(-) diff --git a/components/dashboard/src/service/json-rpc-workspace-client.ts b/components/dashboard/src/service/json-rpc-workspace-client.ts index 4622aa1f554c33..8dab49b9346edb 100644 --- a/components/dashboard/src/service/json-rpc-workspace-client.ts +++ b/components/dashboard/src/service/json-rpc-workspace-client.ts @@ -10,8 +10,8 @@ import { WorkspaceService } from "@gitpod/public-api/lib/gitpod/experimental/v2/ import { GetWorkspaceRequest, GetWorkspaceResponse, - WatchWorkspaceRequest, - WatchWorkspaceResponse, + WatchWorkspaceStatusRequest, + WatchWorkspaceStatusResponse, } from "@gitpod/public-api/lib/gitpod/experimental/v2/workspace_pb"; import { converter } from "./public-api"; import { getGitpodService } from "./service"; @@ -30,10 +30,10 @@ export class JsonRpcWorkspaceClient implements PromiseClient, + async *watchWorkspaceStatus( + request: PartialMessage, options?: CallOptions, - ): AsyncIterable { + ): AsyncIterable { if (!options?.signal) { throw new ConnectError("signal is required", Code.InvalidArgument); } @@ -48,15 +48,27 @@ export class JsonRpcWorkspaceClient implements PromiseClient { - // TODO: if id provided, send init one - // TODO: will we sent stale status? - const it = this.workspaceService.watchWorkspaces(context.user.id, { signal: context.signal }); + async *watchWorkspaceStatus( + req: WatchWorkspaceStatusRequest, + context: HandlerContext, + ): AsyncIterable { + if (req.workspaceId) { + const instance = await this.workspaceService.getCurrentInstance(context.user.id, req.workspaceId); + const status = this.apiConverter.toWorkspace(instance).status; + if (status) { + const response = new WatchWorkspaceStatusResponse(); + response.status = status; + yield response; + } + } + const it = this.workspaceService.watchWorkspaceStatus(context.user.id, { signal: context.signal }); for await (const instance of it) { if (!instance) { continue; } - if (req.id && instance.workspaceId !== req.id) { + if (req.workspaceId && instance.workspaceId !== req.workspaceId) { + continue; + } + const status = this.apiConverter.toWorkspace(instance).status; + if (!status) { continue; } - const response = new WatchWorkspaceResponse(); - response.item = this.apiConverter.toWorkspace(instance); + const response = new WatchWorkspaceStatusResponse(); + response.status = status; yield response; } } diff --git a/components/server/src/workspace/workspace-service.ts b/components/server/src/workspace/workspace-service.ts index b81f2825355afc..af8dc1f7d4497f 100644 --- a/components/server/src/workspace/workspace-service.ts +++ b/components/server/src/workspace/workspace-service.ts @@ -734,8 +734,7 @@ export class WorkspaceService { return urls; } - public watchWorkspaces(userId: string, opts: { signal: AbortSignal }) { - // this.doGetWorkspace + public watchWorkspaceStatus(userId: string, opts: { signal: AbortSignal }) { return generateAsyncGenerator((sink) => { const dispose = this.subscriber.listenForWorkspaceInstanceUpdates(userId, (_ctx, instance) => { sink.next(instance);