From: Jérôme Benoit Date: Sun, 27 Aug 2023 14:50:22 +0000 (+0200) Subject: refactor: factor out task execution semantic with tasks queue X-Git-Tag: v2.6.37~31 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=375f7504cdd1e27b29c47f6a4ffc0669cab855f3;p=poolifier.git refactor: factor out task execution semantic with tasks queue Signed-off-by: Jérôme Benoit --- diff --git a/src/pools/abstract-pool.ts b/src/pools/abstract-pool.ts index 2820f8e3..be8ec1a0 100644 --- a/src/pools/abstract-pool.ts +++ b/src/pools/abstract-pool.ts @@ -733,6 +733,14 @@ export abstract class AbstractPool< return [] } + private shallExecuteTask (workerNodeKey: number): boolean { + return ( + this.tasksQueueSize(workerNodeKey) === 0 && + this.workerNodes[workerNodeKey].usage.tasks.executing < + (this.opts.tasksQueueOptions?.concurrency as number) + ) + } + /** @inheritDoc */ public async execute ( data?: Data, @@ -780,9 +788,7 @@ export abstract class AbstractPool< if ( this.opts.enableTasksQueue === false || (this.opts.enableTasksQueue === true && - this.tasksQueueSize(workerNodeKey) === 0 && - this.workerNodes[workerNodeKey].usage.tasks.executing < - (this.opts.tasksQueueOptions?.concurrency as number)) + this.shallExecuteTask(workerNodeKey)) ) { this.executeTask(workerNodeKey, task) } else { @@ -1213,11 +1219,7 @@ export abstract class AbstractPool< ...(this.dequeueTask(workerNodeKey) as Task), workerId: destinationWorkerNode.info.id as number } - if ( - this.tasksQueueSize(destinationWorkerNodeKey) === 0 && - destinationWorkerNode.usage.tasks.executing < - (this.opts.tasksQueueOptions?.concurrency as number) - ) { + if (this.shallExecuteTask(destinationWorkerNodeKey)) { this.executeTask(destinationWorkerNodeKey, task) } else { this.enqueueTask(destinationWorkerNodeKey, task) @@ -1248,11 +1250,7 @@ export abstract class AbstractPool< ...(sourceWorkerNode.popTask() as Task), workerId: destinationWorkerNode.info.id as number } - if ( - this.tasksQueueSize(destinationWorkerNodeKey) === 0 && - destinationWorkerNode.usage.tasks.executing < - (this.opts.tasksQueueOptions?.concurrency as number) - ) { + if (this.shallExecuteTask(destinationWorkerNodeKey)) { this.executeTask(destinationWorkerNodeKey, task) } else { this.enqueueTask(destinationWorkerNodeKey, task) @@ -1301,11 +1299,7 @@ export abstract class AbstractPool< ...(sourceWorkerNode.popTask() as Task), workerId: workerNode.info.id as number } - if ( - this.tasksQueueSize(workerNodeKey) === 0 && - workerNode.usage.tasks.executing < - (this.opts.tasksQueueOptions?.concurrency as number) - ) { + if (this.shallExecuteTask(workerNodeKey)) { this.executeTask(workerNodeKey, task) } else { this.enqueueTask(workerNodeKey, task)