X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fpools%2Fcluster%2Ffixed.ts;h=5f067bd7fb4a716f20297f2c907c7632a9607a1b;hb=refs%2Ftags%2Fv3.0.3;hp=20215df650c8ce6102d5ad9eaad3253a7c0ccf63;hpb=72ae84a2c9ccb043ce8b0ca2b83014d47a8120cb;p=poolifier.git diff --git a/src/pools/cluster/fixed.ts b/src/pools/cluster/fixed.ts index 20215df6..5f067bd7 100644 --- a/src/pools/cluster/fixed.ts +++ b/src/pools/cluster/fixed.ts @@ -61,16 +61,17 @@ export class FixedClusterPool< /** @inheritDoc */ protected async destroyWorkerNode (workerNodeKey: number): Promise { + this.flagWorkerNodeAsNotReady(workerNodeKey) this.flushTasksQueue(workerNodeKey) // FIXME: wait for tasks to be finished const workerNode = this.workerNodes[workerNodeKey] const worker = workerNode.worker const waitWorkerExit = new Promise(resolve => { - worker.on('exit', () => { + worker.once('exit', () => { resolve() }) }) - worker.on('disconnect', () => { + worker.once('disconnect', () => { worker.kill() }) await this.sendKillMessageToWorker(workerNodeKey) @@ -85,15 +86,14 @@ export class FixedClusterPool< ): void { this.workerNodes[workerNodeKey].worker.send({ ...message, - workerId: this.workerNodes[workerNodeKey].info.id as number + workerId: this.getWorkerInfo(workerNodeKey).id as number }) } /** @inheritDoc */ protected sendStartupMessageToWorker (workerNodeKey: number): void { this.sendToWorker(workerNodeKey, { - ready: false, - workerId: this.workerNodes[workerNodeKey].info.id as number + ready: false }) } @@ -105,6 +105,22 @@ export class FixedClusterPool< this.workerNodes[workerNodeKey].worker.on('message', listener) } + /** @inheritDoc */ + protected registerOnceWorkerMessageListener( + workerNodeKey: number, + listener: (message: MessageValue) => void + ): void { + this.workerNodes[workerNodeKey].worker.once('message', listener) + } + + /** @inheritDoc */ + protected deregisterWorkerMessageListener( + workerNodeKey: number, + listener: (message: MessageValue) => void + ): void { + this.workerNodes[workerNodeKey].worker.off('message', listener) + } + /** @inheritDoc */ protected createWorker (): Worker { return cluster.fork(this.opts.env)