If `killBehavior` is set to `KillBehaviors.SOFT` your tasks have no timeout and your workers will not be terminated until your task is completed.
Default: `60000`
-- `killBehavior` (optional) - Dictates if your async unit (worker/process) will be deleted in case that a task is active on it.
+- `killBehavior` (optional) - Dictates if your worker will be deleted in case that a task is active on it.
**KillBehaviors.SOFT**: If `currentTime - lastActiveTime` is greater than `maxInactiveTime` but a task is still executing or queued, then the worker **won't** be deleted.
**KillBehaviors.HARD**: If `currentTime - lastActiveTime` is greater than `maxInactiveTime` but a task is still executing or queued, then the worker will be deleted.
This option only apply to the newly created workers.
) {
const workerWeight =
this.opts.weights?.[workerNodeKey] ?? this.defaultWorkerWeight
- // if (this.isWorkerNodeReady(workerNodeKey) && workerWeight >= this.roundWeights[roundIndex]) {
- if (workerWeight >= this.roundWeights[roundIndex]) {
+ if (
+ this.isWorkerNodeReady(workerNodeKey) &&
+ workerWeight >= this.roundWeights[roundIndex]
+ ) {
roundId = roundIndex
workerNodeId = workerNodeKey
break
*/
async?: boolean
/**
- * `killBehavior` dictates if your async unit (worker/process) will be deleted in case that a task is active on it.
+ * `killBehavior` dictates if your worker will be deleted in case that a task is active on it.
*
* - SOFT: If `currentTime - lastActiveTime` is greater than `maxInactiveTime` but a task is still executing or queued, then the worker **won't** be deleted.
* - HARD: If `currentTime - lastActiveTime` is greater than `maxInactiveTime` but a task is still executing or queued, then the worker will be deleted.
)
let poolReady = 0
pool1.emitter.on(PoolEvents.ready, () => ++poolReady)
- await waitPoolEvents(pool1, PoolEvents.ready, 1)
+ if (!pool1.info.ready) {
+ await waitPoolEvents(pool1, PoolEvents.ready, 1)
+ }
expect(poolReady).toBe(1)
})
DynamicThreadPool,
FixedClusterPool,
FixedThreadPool,
+ PoolEvents,
WorkerChoiceStrategies
} = require('../../../lib')
const { CircularArray } = require('../../../lib/circular-array')
+const { waitPoolEvents } = require('../../test-utils')
describe('Selection strategies test suite', () => {
const min = 0
WorkerChoiceStrategies.INTERLEAVED_WEIGHTED_ROUND_ROBIN
}
)
+ if (!pool.info.ready) {
+ await waitPoolEvents(pool, PoolEvents.ready, 1)
+ }
// TODO: Create a better test to cover `InterleavedWeightedRoundRobinWorkerChoiceStrategy#choose`
const promises = new Set()
const maxMultiplier = 2
WorkerChoiceStrategies.INTERLEAVED_WEIGHTED_ROUND_ROBIN
}
)
+ if (!pool.info.ready) {
+ await waitPoolEvents(pool, PoolEvents.ready, 1)
+ }
// TODO: Create a better test to cover `InterleavedWeightedRoundRobinWorkerChoiceStrategy#choose`
const promises = new Set()
const maxMultiplier = 2
for (const workerNode of pool.workerNodes) {
expect(workerNode.usage).toStrictEqual({
tasks: {
- executed: maxMultiplier,
+ executed: expect.any(Number),
executing: 0,
queued: 0,
maxQueued: 0,
pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
pool.workerChoiceStrategyContext.workerChoiceStrategy
).nextWorkerNodeKey
- ).toBe(0)
+ ).toBe(1)
expect(
pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
pool.workerChoiceStrategyContext.workerChoiceStrategy
)
let poolReady = 0
pool1.emitter.on(PoolEvents.ready, () => ++poolReady)
- await waitPoolEvents(pool1, PoolEvents.ready, 1)
+ if (!pool1.info.ready) {
+ await waitPoolEvents(pool1, PoolEvents.ready, 1)
+ }
expect(poolReady).toBe(1)
})