- `maxInactiveTime` (optional) - Max time to wait tasks to work on in milliseconds, after this period the new worker will die.
The last active time of your worker unit will be updated when a task is submitted to a worker or when a worker terminate a task.
- If `killBehavior` is set to `KillBehaviors.HARD` this value represents also the timeout for the tasks that you submit to the pool, when this timeout expires your tasks is interrupted and the worker is killed if is not part of the minimum size of the pool.
+ If `killBehavior` is set to `KillBehaviors.HARD` this value represents also the timeout for the tasks that you submit to the pool, when this timeout expires your tasks is interrupted before completion and removed. The worker is killed if is not part of the minimum size of the pool.
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`
this.workerNodes.map(async (workerNode, workerNodeKey) => {
this.flushTasksQueue(workerNodeKey)
// FIXME: wait for tasks to be finished
+ const workerExitPromise = new Promise<void>(resolve => {
+ workerNode.worker.on('exit', () => {
+ resolve()
+ })
+ })
await this.destroyWorker(workerNode.worker)
+ await workerExitPromise
})
)
}
}
private flushTasksQueue (workerNodeKey: number): void {
- if (this.tasksQueueSize(workerNodeKey) > 0) {
- for (let i = 0; i < this.tasksQueueSize(workerNodeKey); i++) {
- this.executeTask(
- workerNodeKey,
- this.dequeueTask(workerNodeKey) as Task<Data>
- )
- }
+ while (this.tasksQueueSize(workerNodeKey) > 0) {
+ this.executeTask(
+ workerNodeKey,
+ this.dequeueTask(workerNodeKey) as Task<Data>
+ )
}
this.workerNodes[workerNodeKey].tasksQueue.clear()
}
* Started flag.
*/
started: boolean
+ /**
+ * Shared buffer.
+ */
+ readonly sharedBuffer?: Int32Array
}
/**
longRunningPool.execute()
}
expect(longRunningPool.workerNodes.length).toBe(max)
- await sleep(1500)
+ await sleep(1000)
// Here we expect the workerNodes to be at the max size since the task is still executing
expect(longRunningPool.workerNodes.length).toBe(max)
// We need to clean up the resources after our test
longRunningPool.execute()
}
expect(longRunningPool.workerNodes.length).toBe(max)
- await sleep(1500)
+ await sleep(1000)
// Here we expect the workerNodes to be at the max size since the task is still executing
expect(longRunningPool.workerNodes.length).toBe(max)
// We need to clean up the resources after our test