From edbc15c62f491f28a09a03a4cc134a8a9522059e Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Wed, 13 Sep 2023 19:48:38 +0200 Subject: [PATCH] refactor: use pool side task functions list for hasTaskFunction() MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/pools/abstract-pool.ts | 14 +++++++++----- src/utility-types.ts | 6 ++++-- src/worker/abstract-worker.ts | 4 +--- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/pools/abstract-pool.ts b/src/pools/abstract-pool.ts index 90cede3a..1b53065c 100644 --- a/src/pools/abstract-pool.ts +++ b/src/pools/abstract-pool.ts @@ -737,11 +737,15 @@ export abstract class AbstractPool< /** @inheritDoc */ public hasTaskFunction (name: string): boolean { - this.sendToWorkers({ - taskFunctionOperation: 'has', - taskFunctionName: name - }) - return true + for (const workerNode of this.workerNodes) { + if ( + Array.isArray(workerNode.info.taskFunctionNames) && + workerNode.info.taskFunctionNames.includes(name) + ) { + return true + } + } + return false } /** @inheritDoc */ diff --git a/src/utility-types.ts b/src/utility-types.ts index b2470bea..3d5673f9 100644 --- a/src/utility-types.ts +++ b/src/utility-types.ts @@ -118,12 +118,14 @@ export interface MessageValue readonly taskPerformance?: TaskPerformance /** * Task function operation: - * - `'has'` - Check if a task function exists. * - `'add'` - Add a task function. * - `'delete'` - Delete a task function. * - `'default'` - Set a task function as default. */ - readonly taskFunctionOperation?: 'has' | 'add' | 'remove' | 'default' + readonly taskFunctionOperation?: 'add' | 'remove' | 'default' + /** + * Whether the task function operation is successful or not. + */ readonly taskFunctionOperationStatus?: boolean /** * Task function serialized to string. diff --git a/src/worker/abstract-worker.ts b/src/worker/abstract-worker.ts index 1b64dc4f..8cd370de 100644 --- a/src/worker/abstract-worker.ts +++ b/src/worker/abstract-worker.ts @@ -355,9 +355,7 @@ export abstract class AbstractWorker< ): void { const { taskFunctionOperation, taskFunction, taskFunctionName } = message let response!: TaskFunctionOperationReturnType - if (taskFunctionOperation === 'has') { - response = this.hasTaskFunction(taskFunctionName as string) - } else if (taskFunctionOperation === 'add') { + if (taskFunctionOperation === 'add') { response = this.addTaskFunction( taskFunctionName as string, // eslint-disable-next-line @typescript-eslint/no-implied-eval, no-new-func -- 2.34.1