Skip to content

Commit

Permalink
address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
mustard-mh committed Nov 7, 2023
1 parent b9c02d9 commit ef17d55
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 19 deletions.
28 changes: 20 additions & 8 deletions components/dashboard/src/service/json-rpc-workspace-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -30,10 +30,10 @@ export class JsonRpcWorkspaceClient implements PromiseClient<typeof WorkspaceSer
return result;
}

async *watchWorkspace(
request: PartialMessage<WatchWorkspaceRequest>,
async *watchWorkspaceStatus(
request: PartialMessage<WatchWorkspaceStatusRequest>,
options?: CallOptions,
): AsyncIterable<WatchWorkspaceResponse> {
): AsyncIterable<WatchWorkspaceStatusResponse> {
if (!options?.signal) {
throw new ConnectError("signal is required", Code.InvalidArgument);
}
Expand All @@ -48,15 +48,27 @@ export class JsonRpcWorkspaceClient implements PromiseClient<typeof WorkspaceSer
},
{ signal: options.signal },
);
if (request.workspaceId) {
const resp = await this.getWorkspace({ id: request.workspaceId });
if (resp.item?.status) {
const response = new WatchWorkspaceStatusResponse();
response.status = resp.item.status;
yield response;
}
}
for await (const item of it) {
if (!item) {
continue;
}
if (request.id && item.workspaceId !== request.id) {
if (request.workspaceId && item.workspaceId !== request.workspaceId) {
continue;
}
const status = converter.toWorkspace(item).status;
if (!status) {
continue;
}
const response = new WatchWorkspaceResponse();
response.item = converter.toWorkspace(item);
const response = new WatchWorkspaceStatusResponse();
response.status = status;
yield response;
}
}
Expand Down
32 changes: 23 additions & 9 deletions components/server/src/api/workspace-service-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import { WorkspaceService as WorkspaceServiceInterface } from "@gitpod/public-ap
import {
GetWorkspaceRequest,
GetWorkspaceResponse,
WatchWorkspaceRequest,
WatchWorkspaceResponse,
WatchWorkspaceStatusRequest,
WatchWorkspaceStatusResponse,
} from "@gitpod/public-api/lib/gitpod/experimental/v2/workspace_pb";

import { inject, injectable } from "inversify";
Expand All @@ -32,19 +32,33 @@ export class WorkspaceServiceAPI implements ServiceImpl<typeof WorkspaceServiceI
return response;
}

async *watchWorkspace(req: WatchWorkspaceRequest, context: HandlerContext): AsyncIterable<WatchWorkspaceResponse> {
// 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<WatchWorkspaceStatusResponse> {
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;
}
}
Expand Down
3 changes: 1 addition & 2 deletions components/server/src/workspace/workspace-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<WorkspaceInstance>((sink) => {
const dispose = this.subscriber.listenForWorkspaceInstanceUpdates(userId, (_ctx, instance) => {
sink.next(instance);
Expand Down

0 comments on commit ef17d55

Please sign in to comment.