From 1e924543e08745cfa9642dca53d303390d391f00 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Mon, 25 Jan 2021 23:39:52 +0100 Subject: [PATCH] Fix worker thread exit message. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/worker/WorkerDynamicPool.ts | 3 +-- src/worker/WorkerSet.ts | 15 +++++++++++++-- src/worker/WorkerStaticPool.ts | 3 +-- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/worker/WorkerDynamicPool.ts b/src/worker/WorkerDynamicPool.ts index 9567768c..570e5d1b 100644 --- a/src/worker/WorkerDynamicPool.ts +++ b/src/worker/WorkerDynamicPool.ts @@ -4,7 +4,6 @@ import Constants from '../utils/Constants'; import Utils from '../utils/Utils'; import { WorkerData } from '../types/Worker'; import Wrk from './Wrk'; -import { threadId } from 'worker_threads'; export default class WorkerDynamicPool extends Wrk { private pool: DynamicPool; @@ -60,7 +59,7 @@ class DynamicPool extends DynamicThreadPool { { exitHandler: (code) => { if (code !== 0) { - console.error(`Worker ${threadId} stopped with exit code ${code}`); + console.error(`Worker stopped with exit code ${code}`); } } } diff --git a/src/worker/WorkerSet.ts b/src/worker/WorkerSet.ts index 2151eff9..0c59c091 100644 --- a/src/worker/WorkerSet.ts +++ b/src/worker/WorkerSet.ts @@ -1,8 +1,8 @@ -import { Worker, threadId } from 'worker_threads'; import { WorkerData, WorkerEvents, WorkerSetElement } from '../types/Worker'; import Constants from '../utils/Constants'; import Utils from '../utils/Utils'; +import { Worker } from 'worker_threads'; import Wrk from './Wrk'; export default class WorkerSet extends Wrk { @@ -65,8 +65,9 @@ export default class WorkerSet extends Wrk { worker.on('error', () => { }); worker.on('exit', (code) => { if (code !== 0) { - console.error(`Worker ${threadId} stopped with exit code ${code}`); + console.error(`Worker stopped with exit code ${code}`); } + // FIXME: remove matching worker set element }); this.workers.add({ worker, numberOfWorkerElements: 0 }); } @@ -81,4 +82,14 @@ export default class WorkerSet extends Wrk { private getLastWorker(): Worker { return this.getLastWorkerSetElement().worker; } + + private getWorkerSetElementByWorker(worker: Worker): WorkerSetElement { + let workerSetElt: WorkerSetElement; + this.workers.forEach((workerSetElement) => { + if (JSON.stringify(workerSetElement.worker) === JSON.stringify(worker)) { + workerSetElt = workerSetElement; + } + }); + return workerSetElt; + } } diff --git a/src/worker/WorkerStaticPool.ts b/src/worker/WorkerStaticPool.ts index 20d53b0e..9c2bc41d 100644 --- a/src/worker/WorkerStaticPool.ts +++ b/src/worker/WorkerStaticPool.ts @@ -4,7 +4,6 @@ import Constants from '../utils/Constants'; import Utils from '../utils/Utils'; import { WorkerData } from '../types/Worker'; import Wrk from './Wrk'; -import { threadId } from 'worker_threads'; export default class WorkerStaticPool extends Wrk { private pool: StaticPool; @@ -60,7 +59,7 @@ class StaticPool extends FixedThreadPool { { exitHandler: (code) => { if (code !== 0) { - console.error(`Worker ${threadId} stopped with exit code ${code}`); + console.error(`Worker stopped with exit code ${code}`); } } } -- 2.34.1