checkFilePath,
checkValidTasksQueueOptions,
checkValidWorkerChoiceStrategy,
- updateMeasurementStatistics
- // waitWorkerNodeEvents
+ updateMeasurementStatistics,
+ waitWorkerNodeEvents
} from './utils'
/**
*/
protected async destroyWorkerNode (workerNodeKey: number): Promise<void> {
this.flagWorkerNodeAsNotReady(workerNodeKey)
- this.flushTasksQueue(workerNodeKey)
+ const flushedTasks = this.flushTasksQueue(workerNodeKey)
const workerNode = this.workerNodes[workerNodeKey]
- // FIXME: wait for tasks to be finished
- // await waitWorkerNodeEvents(
- // workerNode,
- // 'taskFinished',
- // workerNode.usage.tasks.executing
- // )
+ await waitWorkerNodeEvents(workerNode, 'taskFinished', flushedTasks)
await this.sendKillMessageToWorker(workerNodeKey)
await workerNode.terminate()
}
return this.workerNodes[workerNodeKey].tasksQueueSize()
}
- protected flushTasksQueue (workerNodeKey: number): void {
+ protected flushTasksQueue (workerNodeKey: number): number {
+ let flushedTasks = 0
while (this.tasksQueueSize(workerNodeKey) > 0) {
this.executeTask(
workerNodeKey,
this.dequeueTask(workerNodeKey) as Task<Data>
)
+ ++flushedTasks
}
this.workerNodes[workerNodeKey].clearTasksQueue()
+ return flushedTasks
}
private flushTasksQueues (): void {