repositories
/
poolifier.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge branch 'master' of github.com:poolifier/poolifier
[poolifier.git]
/
src
/
pools
/
cluster
/
fixed.ts
diff --git
a/src/pools/cluster/fixed.ts
b/src/pools/cluster/fixed.ts
index 09c5e369a5459d0858559a29eef8e9fc3a563c66..ed4f6fed2826078bfdeac466bcec7e8c4c80bef5 100644
(file)
--- a/
src/pools/cluster/fixed.ts
+++ b/
src/pools/cluster/fixed.ts
@@
-1,9
+1,9
@@
-import type {
Worker } from '
cluster'
-import cluster from 'cluster'
+import type {
ClusterSettings, Worker } from 'node:
cluster'
+import cluster from '
node:
cluster'
import type { MessageValue } from '../../utility-types'
import { AbstractPool } from '../abstract-pool'
import type { PoolOptions } from '../pool'
import type { MessageValue } from '../../utility-types'
import { AbstractPool } from '../abstract-pool'
import type { PoolOptions } from '../pool'
-import { PoolType } from '../pool
-internal
'
+import { PoolType } from '../pool'
/**
* Options for a poolifier cluster pool.
/**
* Options for a poolifier cluster pool.
@@
-16,6
+16,12
@@
export interface ClusterPoolOptions extends PoolOptions<Worker> {
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
env?: any
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
env?: any
+ /**
+ * Cluster settings.
+ *
+ * @see https://nodejs.org/api/cluster.html#cluster_cluster_settings
+ */
+ settings?: ClusterSettings
}
/**
}
/**
@@
-25,8
+31,8
@@
export interface ClusterPoolOptions extends PoolOptions<Worker> {
*
* This pool selects the workers in a round robin fashion.
*
*
* This pool selects the workers in a round robin fashion.
*
- * @t
emplate Data
Type of data sent to the worker. This can only be serializable data.
- * @t
emplate ResponseType of response of execution
. This can only be serializable data.
+ * @t
ypeParam Data -
Type of data sent to the worker. This can only be serializable data.
+ * @t
ypeParam Response - Type of execution response
. This can only be serializable data.
* @author [Christopher Quadflieg](https://github.com/Shinigami92)
* @since 2.0.0
*/
* @author [Christopher Quadflieg](https://github.com/Shinigami92)
* @since 2.0.0
*/
@@
-37,9
+43,9
@@
export class FixedClusterPool<
/**
* Constructs a new poolifier fixed cluster pool.
*
/**
* Constructs a new poolifier fixed cluster pool.
*
- * @param numberOfWorkers Number of workers for this pool.
- * @param filePath Path to an implementation of a `ClusterWorker` file, which can be relative or absolute.
- * @param
[opts={}]
Options for this fixed cluster pool.
+ * @param numberOfWorkers
-
Number of workers for this pool.
+ * @param filePath
-
Path to an implementation of a `ClusterWorker` file, which can be relative or absolute.
+ * @param
opts -
Options for this fixed cluster pool.
*/
public constructor (
numberOfWorkers: number,
*/
public constructor (
numberOfWorkers: number,
@@
-51,9
+57,7
@@
export class FixedClusterPool<
/** @inheritDoc */
protected setupHook (): void {
/** @inheritDoc */
protected setupHook (): void {
- cluster.setupPrimary({
- exec: this.filePath
- })
+ cluster.setupPrimary({ ...this.opts.settings, exec: this.filePath })
}
/** @inheritDoc */
}
/** @inheritDoc */
@@
-62,7
+66,7
@@
export class FixedClusterPool<
}
/** @inheritDoc */
}
/** @inheritDoc */
- p
ublic
destroyWorker (worker: Worker): void {
+ p
rotected
destroyWorker (worker: Worker): void {
this.sendToWorker(worker, { kill: 1 })
worker.kill()
}
this.sendToWorker(worker, { kill: 1 })
worker.kill()
}
@@
-73,7
+77,7
@@
export class FixedClusterPool<
}
/** @inheritDoc */
}
/** @inheritDoc */
- p
ublic registerWorkerMessageListener<Message extends Data | Response>
(
+ p
rotected registerWorkerMessageListener<Message extends Data | Response>
(
worker: Worker,
listener: (message: MessageValue<Message>) => void
): void {
worker: Worker,
listener: (message: MessageValue<Message>) => void
): void {
@@
-87,7
+91,7
@@
export class FixedClusterPool<
/** @inheritDoc */
protected afterWorkerSetup (worker: Worker): void {
/** @inheritDoc */
protected afterWorkerSetup (worker: Worker): void {
- // Listen worker messages.
+ // Listen
to
worker messages.
this.registerWorkerMessageListener(worker, super.workerListener())
}
this.registerWorkerMessageListener(worker, super.workerListener())
}
@@
-97,7
+101,12
@@
export class FixedClusterPool<
}
/** @inheritDoc */
}
/** @inheritDoc */
- public get busy (): boolean {
- return this.internalGetBusyStatus()
+ protected get full (): boolean {
+ return this.workerNodes.length === this.numberOfWorkers
+ }
+
+ /** @inheritDoc */
+ protected get busy (): boolean {
+ return this.internalBusy()
}
}
}
}