From ca7a062a3219e3a0c3714c55a1a7f0d84a0b570c Mon Sep 17 00:00:00 2001 From: LayneHaber Date: Tue, 18 Aug 2020 14:09:17 -0600 Subject: [PATCH 1/2] fix --- src/client.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/client.ts b/src/client.ts index 6431697..e5b699c 100644 --- a/src/client.ts +++ b/src/client.ts @@ -31,6 +31,8 @@ export default class Client { private subscriber: Subscriber; private connecting = false; private logLevel: number; + private cleanUpInterval: NodeJS.Timeout | undefined; + private cleaningUp = false; constructor(opts: InitClientManagerOptions) { this.subscriber = new Subscriber(opts.logger, opts.store); @@ -42,6 +44,8 @@ export default class Client { rootStoreDir: string, opts: InternalConnectOptions, ): Promise { + if (this.cleaningUp) throw new Error(`Client is cleaning up`); + if (this.connecting) { throw new Error(`Client is connecting`); } @@ -70,9 +74,26 @@ export default class Client { return client; } finally { this.connecting = false; + this.scheduleCleanup(); } } + public scheduleCleanup(): void { + if (typeof this.cleanUpInterval !== "undefined") clearInterval(this.cleanUpInterval); + this.cleanUpInterval = setInterval( + this.cleanupRegistryApps, + 86_400_000, // 24 hours + ); + } + + public async cleanupRegistryApps(): Promise { + const client = this.getClient(); + this.cleaningUp = true; + // TODO: expose method in Connext client + await client.cleanupRegistryApps(); + this.cleaningUp = false; + } + public getConfig(): RouteMethods.GetConfigResponse { const client = this.getClient(); const config = { @@ -307,6 +328,7 @@ export default class Client { if (!this.client) { throw new Error("Client is not initialized"); } + if (this.cleaningUp) throw new Error(`Client is cleanning up`); return this.client; } } From 52b14221e15b8244edffdef3ae37a4b30402fc65 Mon Sep 17 00:00:00 2001 From: Pedro Gomes Date: Wed, 19 Aug 2020 21:25:02 +0200 Subject: [PATCH 2/2] type cast --- src/client.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/client.ts b/src/client.ts index f5d5978..4f2eef2 100644 --- a/src/client.ts +++ b/src/client.ts @@ -90,8 +90,7 @@ export default class Client { public async cleanupRegistryApps(): Promise { const client = this.getClient(); this.cleaningUp = true; - // TODO: expose method in Connext client - await client.cleanupRegistryApps(); + await (client as connext.ConnextClient).cleanupRegistryApps(); this.cleaningUp = false; }