From: Jérôme Benoit Date: Wed, 13 Sep 2023 17:48:38 +0000 (+0200) Subject: refactor: use pool side task functions list for hasTaskFunction() X-Git-Tag: v2.7.0~1^2~40 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=edbc15c62f491f28a09a03a4cc134a8a9522059e;hp=-c;p=poolifier.git refactor: use pool side task functions list for hasTaskFunction() Signed-off-by: Jérôme Benoit --- edbc15c62f491f28a09a03a4cc134a8a9522059e 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