X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fpools%2Fabstract-pool.ts;h=b9a7cd398920fc77a754d3d4047414beae94ba46;hb=88d983fa5c8db26fa52b8a69a2b724ade989db9b;hp=5114bead6d4670af440b5d66f5af22bfa5aa213f;hpb=b0d6ed8f66e9636805462c83e4c9290dccebb690;p=poolifier.git diff --git a/src/pools/abstract-pool.ts b/src/pools/abstract-pool.ts index 5114bead..b9a7cd39 100644 --- a/src/pools/abstract-pool.ts +++ b/src/pools/abstract-pool.ts @@ -146,6 +146,9 @@ export abstract class AbstractPool< this.opts.workerChoiceStrategyOptions = opts.workerChoiceStrategyOptions ?? DEFAULT_WORKER_CHOICE_STRATEGY_OPTIONS + this.checkValidWorkerChoiceStrategyOptions( + this.opts.workerChoiceStrategyOptions + ) this.opts.enableEvents = opts.enableEvents ?? true this.opts.enableTasksQueue = opts.enableTasksQueue ?? false if (this.opts.enableTasksQueue) { @@ -179,6 +182,14 @@ export abstract class AbstractPool< 'Invalid worker choice strategy options: must be a plain object' ) } + if ( + workerChoiceStrategyOptions.weights != null && + Object.keys(workerChoiceStrategyOptions.weights).length !== this.size + ) { + throw new Error( + 'Invalid worker choice strategy options: must have a weight for each worker node' + ) + } } private checkValidTasksQueueOptions ( @@ -429,8 +440,11 @@ export abstract class AbstractPool< workerTasksUsage.avgRunTime = workerTasksUsage.runTime / workerTasksUsage.run } - if (this.workerChoiceStrategyContext.getRequiredStatistics().medRunTime) { - workerTasksUsage.runTimeHistory.push(message.runTime ?? 0) + if ( + this.workerChoiceStrategyContext.getRequiredStatistics().medRunTime && + message.runTime != null + ) { + workerTasksUsage.runTimeHistory.push(message.runTime) workerTasksUsage.medRunTime = median(workerTasksUsage.runTimeHistory) } }