From: Jérôme Benoit Date: Mon, 25 Jan 2021 22:39:52 +0000 (+0100) Subject: Fix worker thread exit message. X-Git-Tag: v1.0.1-0~109 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=1e924543e08745cfa9642dca53d303390d391f00;p=e-mobility-charging-stations-simulator.git Fix worker thread exit message. Signed-off-by: Jérôme Benoit --- 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}`); } } }