'node:cluster',
'node:crypto',
'node:events',
+ 'node:fs',
'node:os',
'node:perf_hooks',
'node:worker_threads'
import { randomUUID } from 'node:crypto'
import { performance } from 'node:perf_hooks'
+import { existsSync } from 'node:fs'
import type {
MessageValue,
PromiseResponseWrapper,
private checkFilePath (filePath: string): void {
if (
filePath == null ||
+ typeof filePath !== 'string' ||
(typeof filePath === 'string' && filePath.trim().length === 0)
) {
throw new Error('Please specify a file with a worker implementation')
}
+ if (!existsSync(filePath)) {
+ throw new Error(`Cannot find the worker file '${filePath}'`)
+ }
}
private checkNumberOfWorkers (numberOfWorkers: number): void {
) {
const workerWeight =
this.opts.weights?.[workerNodeKey] ?? this.defaultWorkerWeight
+ // if (this.isWorkerNodeReady(workerNodeKey) && workerWeight >= this.roundWeights[roundIndex]) {
if (workerWeight >= this.roundWeights[roundIndex]) {
roundId = roundIndex
workerNodeId = workerNodeKey
this.checkAlive.bind(this),
(this.opts.maxInactiveTime ?? DEFAULT_MAX_INACTIVE_TIME) / 2
)
- this.checkAlive.bind(this)()
}
/**
FixedClusterPool,
FixedThreadPool,
PoolEvents,
- WorkerChoiceStrategies,
PoolTypes,
+ WorkerChoiceStrategies,
WorkerTypes
} = require('../../../lib')
const { CircularArray } = require('../../../lib/circular-array')
expect(() => new FixedThreadPool(numberOfWorkers, '')).toThrowError(
expectedError
)
+ expect(() => new FixedThreadPool(numberOfWorkers, 0)).toThrowError(
+ expectedError
+ )
+ expect(() => new FixedThreadPool(numberOfWorkers, true)).toThrowError(
+ expectedError
+ )
+ expect(
+ () => new FixedThreadPool(numberOfWorkers, './dummyWorker.ts')
+ ).toThrowError(new Error("Cannot find the worker file './dummyWorker.ts'"))
})
it('Verify that numberOfWorkers is checked', () => {
const { expect } = require('expect')
const {
- WorkerChoiceStrategies,
DynamicThreadPool,
+ FixedClusterPool,
FixedThreadPool,
- FixedClusterPool
+ WorkerChoiceStrategies
} = require('../../../lib')
const { CircularArray } = require('../../../lib/circular-array')