From 56e35df84d404bd510d44fb9b9767354e2e5b452 Mon Sep 17 00:00:00 2001 From: Louis Date: Wed, 6 Nov 2024 13:34:11 +0700 Subject: [PATCH] chore: clean dangling process on exit and relaunch --- .../inference-cortex-extension/src/index.ts | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/extensions/inference-cortex-extension/src/index.ts b/extensions/inference-cortex-extension/src/index.ts index fb2ee9a461..e099aae444 100644 --- a/extensions/inference-cortex-extension/src/index.ts +++ b/extensions/inference-cortex-extension/src/index.ts @@ -50,12 +50,18 @@ export default class JanInferenceCortexExtension extends LocalOAIEngine { // Run the process watchdog const systemInfo = await systemInformation() + await this.clean() await executeOnMain(NODE, 'run', systemInfo) this.queue.add(() => this.healthz()) + + window.addEventListener('beforeunload', () => { + this.clean() + }) } onUnload(): void { + this.clean() executeOnMain(NODE, 'dispose') super.onUnload() } @@ -132,6 +138,20 @@ export default class JanInferenceCortexExtension extends LocalOAIEngine { }) .then(() => {}) } + + /** + * Clean cortex processes + * @returns + */ + clean(): Promise { + return ky + .delete(`${CORTEX_API_URL}/processmanager/destroy`, { + timeout: 2000, // maximum 2 seconds + }) + .catch(() => { + // Do nothing + }) + } } /// Legacy