From: Jérôme Benoit Date: Wed, 19 Jul 2023 18:03:13 +0000 (+0200) Subject: refactor: add helper to get worker info by worker X-Git-Tag: v2.6.19~12 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=e221309acbe375b6e06fd05f355491f699d1202d;p=poolifier.git refactor: add helper to get worker info by worker Signed-off-by: Jérôme Benoit --- diff --git a/src/pools/abstract-pool.ts b/src/pools/abstract-pool.ts index 5481099f..10a2d514 100644 --- a/src/pools/abstract-pool.ts +++ b/src/pools/abstract-pool.ts @@ -910,7 +910,7 @@ export abstract class AbstractPool< void (this.destroyWorker(worker) as Promise) } }) - const workerInfo = this.getWorkerInfo(this.getWorkerNodeKey(worker)) + const workerInfo = this.getWorkerInfoByWorker(worker) workerInfo.dynamic = true if (this.workerChoiceStrategyContext.getStrategyPolicy().useDynamicWorker) { workerInfo.ready = true @@ -953,7 +953,7 @@ export abstract class AbstractPool< private sendWorkerStartupMessage (worker: Worker): void { this.sendToWorker(worker, { ready: false, - workerId: this.getWorkerInfo(this.getWorkerNodeKey(worker)).id as number + workerId: this.getWorkerInfoByWorker(worker).id as number }) } @@ -1006,9 +1006,9 @@ export abstract class AbstractPool< } private handleWorkerReadyResponse (message: MessageValue): void { - const worker = this.getWorkerById(message.workerId) - this.getWorkerInfo(this.getWorkerNodeKey(worker as Worker)).ready = - message.ready as boolean + this.getWorkerInfoByWorker( + this.getWorkerById(message.workerId) as Worker + ).ready = message.ready as boolean if (this.emitter != null && this.ready) { this.emitter.emit(PoolEvents.ready, this.info) } @@ -1051,7 +1051,7 @@ export abstract class AbstractPool< } /** - * Gets the worker information. + * Gets the worker information from the given worker node key. * * @param workerNodeKey - The worker node key. */ @@ -1059,6 +1059,15 @@ export abstract class AbstractPool< return this.workerNodes[workerNodeKey].info } + /** + * Gets the worker information from the given worker. + * + * @param worker - The worker. + */ + private getWorkerInfoByWorker (worker: Worker): WorkerInfo { + return this.workerNodes[this.getWorkerNodeKey(worker)].info + } + /** * Adds the given worker in the pool worker nodes. * @@ -1135,7 +1144,7 @@ export abstract class AbstractPool< elu: this.workerChoiceStrategyContext.getTaskStatisticsRequirements() .elu.aggregate }, - workerId: this.getWorkerInfo(this.getWorkerNodeKey(worker)).id as number + workerId: this.getWorkerInfoByWorker(worker).id as number }) } }