X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fpools%2Fcluster%2Ffixed.ts;h=46cabdcb75787700bab966bed3ce3312056659ad;hb=55d7d6002049be09a06b08da26febe2e8bfa494b;hp=5f067bd7fb4a716f20297f2c907c7632a9607a1b;hpb=ae3ab61d14adc1f0511e8dea1f69a1d44e7effdf;p=poolifier.git diff --git a/src/pools/cluster/fixed.ts b/src/pools/cluster/fixed.ts index 5f067bd7..46cabdcb 100644 --- a/src/pools/cluster/fixed.ts +++ b/src/pools/cluster/fixed.ts @@ -1,27 +1,9 @@ -import cluster, { type ClusterSettings, type Worker } from 'node:cluster' +import cluster, { type Worker } from 'node:cluster' import type { MessageValue } from '../../utility-types' import { AbstractPool } from '../abstract-pool' import { type PoolOptions, type PoolType, PoolTypes } from '../pool' import { type WorkerType, WorkerTypes } from '../worker' -/** - * Options for a poolifier cluster pool. - */ -export interface ClusterPoolOptions extends PoolOptions { - /** - * Key/value pairs to add to worker process environment. - * - * @see https://nodejs.org/api/cluster.html#cluster_cluster_fork_env - */ - env?: Record - /** - * Cluster settings. - * - * @see https://nodejs.org/api/cluster.html#cluster_cluster_settings - */ - settings?: ClusterSettings -} - /** * A cluster pool with a fixed number of workers. * @@ -44,7 +26,7 @@ export class FixedClusterPool< public constructor ( numberOfWorkers: number, filePath: string, - protected readonly opts: ClusterPoolOptions = {} + protected readonly opts: PoolOptions = {} ) { super(numberOfWorkers, filePath, opts) } @@ -59,26 +41,6 @@ export class FixedClusterPool< return cluster.isPrimary } - /** @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.once('exit', () => { - resolve() - }) - }) - worker.once('disconnect', () => { - worker.kill() - }) - await this.sendKillMessageToWorker(workerNodeKey) - worker.disconnect() - await waitWorkerExit - } - /** @inheritDoc */ protected sendToWorker ( workerNodeKey: number, @@ -121,11 +83,6 @@ export class FixedClusterPool< this.workerNodes[workerNodeKey].worker.off('message', listener) } - /** @inheritDoc */ - protected createWorker (): Worker { - return cluster.fork(this.opts.env) - } - /** @inheritDoc */ protected get type (): PoolType { return PoolTypes.fixed