From 8c6d938de09a601c49febcbfc3f84e71f70b2c51 Mon Sep 17 00:00:00 2001 From: Gero Posmyk-Leinemann Date: Thu, 17 Feb 2022 11:47:57 +0000 Subject: [PATCH] [bridge] Fix PreparingUpdateEmulator initialization --- components/ws-manager-bridge/src/bridge.ts | 9 ++++++--- components/ws-manager-bridge/src/container-module.ts | 4 ++-- .../ws-manager-bridge/src/preparing-update-emulator.ts | 2 ++ 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/components/ws-manager-bridge/src/bridge.ts b/components/ws-manager-bridge/src/bridge.ts index 9913af72032701..e3ade2936f101d 100644 --- a/components/ws-manager-bridge/src/bridge.ts +++ b/components/ws-manager-bridge/src/bridge.ts @@ -4,7 +4,7 @@ * See License-AGPL.txt in the project root for license information. */ -import { inject, injectable } from "inversify"; +import { inject, injectable, interfaces } from "inversify"; import { MessageBusIntegration } from "./messagebus-integration"; import { Disposable, WorkspaceInstance, Queue, WorkspaceInstancePort, PortVisibility, RunningWorkspaceInfo, DisposableCollection } from "@gitpod/gitpod-protocol"; import { WorkspaceStatus, WorkspacePhase, GetWorkspacesRequest, WorkspaceConditionBool, PortVisibility as WsManPortVisibility, WorkspaceType, PromisifiedWorkspaceManagerClient } from "@gitpod/ws-manager/lib"; @@ -20,7 +20,7 @@ import { Timestamp } from "google-protobuf/google/protobuf/timestamp_pb"; import { Configuration } from "./config"; import { WorkspaceCluster } from "@gitpod/gitpod-protocol/lib/workspace-cluster"; import { repeat } from "@gitpod/gitpod-protocol/lib/util/repeat"; -import { PreparingUpdateEmulator } from "./preparing-update-emulator"; +import { PreparingUpdateEmulator, PreparingUpdateEmulatorFactory } from "./preparing-update-emulator"; export const WorkspaceManagerBridgeFactory = Symbol("WorkspaceManagerBridgeFactory"); @@ -51,6 +51,9 @@ export class WorkspaceManagerBridge implements Disposable { @inject(Configuration) protected readonly config: Configuration; + @inject(PreparingUpdateEmulatorFactory) + protected readonly preparingUpdateEmulatorFactory: interfaces.Factory; + @inject(IAnalyticsWriter) protected readonly analytics: IAnalyticsWriter; @@ -88,7 +91,7 @@ export class WorkspaceManagerBridge implements Disposable { startStatusUpdateHandler(false); // emulate WorkspaceInstance updates for all Workspaces in the "preparing" phase in this cluster - const updateEmulator = new PreparingUpdateEmulator(); + const updateEmulator = this.preparingUpdateEmulatorFactory() as PreparingUpdateEmulator; this.disposables.push(updateEmulator); updateEmulator.start(cluster.name); } diff --git a/components/ws-manager-bridge/src/container-module.ts b/components/ws-manager-bridge/src/container-module.ts index 24b889014d49b3..56a9c91baa9295 100644 --- a/components/ws-manager-bridge/src/container-module.ts +++ b/components/ws-manager-bridge/src/container-module.ts @@ -25,7 +25,7 @@ import { newAnalyticsWriterFromEnv } from '@gitpod/gitpod-protocol/lib/util/anal import { MetaInstanceController } from './meta-instance-controller'; import { IClientCallMetrics } from '@gitpod/content-service/lib/client-call-metrics'; import { PrometheusClientCallMetrics } from "@gitpod/gitpod-protocol/lib/messaging/client-call-metrics"; -import { PreparingUpdateEmulator } from './preparing-update-emulator'; +import { PreparingUpdateEmulator, PreparingUpdateEmulatorFactory } from './preparing-update-emulator'; export const containerModule = new ContainerModule(bind => { @@ -70,5 +70,5 @@ export const containerModule = new ContainerModule(bind => { bind(IAnalyticsWriter).toDynamicValue(newAnalyticsWriterFromEnv).inSingletonScope(); - bind(PreparingUpdateEmulator).toSelf().inSingletonScope(); + bind(PreparingUpdateEmulatorFactory).toAutoFactory(PreparingUpdateEmulator); }); diff --git a/components/ws-manager-bridge/src/preparing-update-emulator.ts b/components/ws-manager-bridge/src/preparing-update-emulator.ts index 53f3424c390ccf..c1b3a1230fe213 100644 --- a/components/ws-manager-bridge/src/preparing-update-emulator.ts +++ b/components/ws-manager-bridge/src/preparing-update-emulator.ts @@ -14,6 +14,8 @@ import { MessageBusIntegration } from "./messagebus-integration"; import { GarbageCollectedCache } from "@gitpod/gitpod-protocol/lib/util/garbage-collected-cache"; import * as crypto from 'crypto'; +export const PreparingUpdateEmulatorFactory = Symbol("PreparingUpdateEmulatorFactory"); + interface CacheEntry { instance: WorkspaceInstance, userId: string,