Skip to content
This repository has been archived by the owner on Aug 25, 2021. It is now read-only.

Renames the callback & remove redundant checks #32

Merged
merged 3 commits into from
Aug 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions src/node/services/API/workspace-watcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,14 @@ export class NodeDevWorkspaceWatcher implements IDevWorkspaceWatcher {
const path = `/apis/${devWorkspaceApiGroup}/${devworkspaceVersion}/watch/namespaces/${namespace}/devworkspaces`;

return this.customObjectWatch.watch(path, {}, (type: string, devworkspace: IDevWorkspace) => {
const status = devworkspace!.status!.phase;
const workspaceId = devworkspace!.status!.devworkspaceId;
if (devworkspace.kind !== 'DevWorkspace' || !workspaceId || !status) {
return;
}

if (type === 'ADDED') {
callbacks.onAdded(devworkspace);
} else if (type === 'MODIFIED') {
callbacks.onStatusChange({ workspaceId, status });
callbacks.onModified(devworkspace);
} else if (type === 'DELETED') {
if (status === 'Terminating') {
callbacks.onDeleted(workspaceId);
}
callbacks.onDeleted(workspaceId);
} else {
callbacks.onError(`Error: Unknown type '${type}'.`);
}
Expand Down
4 changes: 2 additions & 2 deletions src/node/services/helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ export async function findApi(apisApi: k8s.ApisApi, apiName: string, version?: s
}
}

export async function delay(ms = 500): Promise<void> {
export async function delay(ms: number = 500): Promise<void> {
await new Promise<void>(resolve => setTimeout(resolve, ms));
};
}
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export interface IDevWorkspaceClient {
}

export type IDevWorkspaceCallbacks = {
onStatusChange: (statusUpdate: { status: string; workspaceId: string }) => void;
onModified: (workspace: IDevWorkspace) => void;
onDeleted: (workspaceId: string) => void;
onAdded: (workspace: IDevWorkspace) => void;
onError: (error: string) => void;
Expand Down