repositories
/
poolifier.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
docs: enhance documentation
[poolifier.git]
/
src
/
pools
/
cluster
/
fixed.ts
diff --git
a/src/pools/cluster/fixed.ts
b/src/pools/cluster/fixed.ts
index 971116bc27cfbd3cd470faa83a904a3949984920..81e7b3b7d08b4bb5624d993a15f7850d9d3bf2ba 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 Response
Type 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 response of execution. 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,
@@
-49,55
+55,58
@@
export class FixedClusterPool<
super(numberOfWorkers, filePath, opts)
}
super(numberOfWorkers, filePath, opts)
}
- /** @inherit
d
oc */
+ /** @inherit
D
oc */
protected setupHook (): void {
protected setupHook (): void {
- cluster.setupPrimary({
- exec: this.filePath
- })
+ cluster.setupPrimary({ ...this.opts.settings, exec: this.filePath })
}
}
- /** @inherit
d
oc */
+ /** @inherit
D
oc */
protected isMain (): boolean {
return cluster.isPrimary
}
protected isMain (): boolean {
return cluster.isPrimary
}
- /** @inherit
d
oc */
+ /** @inherit
D
oc */
public destroyWorker (worker: Worker): void {
this.sendToWorker(worker, { kill: 1 })
worker.kill()
}
public destroyWorker (worker: Worker): void {
this.sendToWorker(worker, { kill: 1 })
worker.kill()
}
- /** @inherit
d
oc */
+ /** @inherit
D
oc */
protected sendToWorker (worker: Worker, message: MessageValue<Data>): void {
worker.send(message)
}
protected sendToWorker (worker: Worker, message: MessageValue<Data>): void {
worker.send(message)
}
- /** @inherit
d
oc */
- p
ublic registerWorkerMessageListener<Message extends Data | Response>
(
+ /** @inherit
D
oc */
+ p
rotected registerWorkerMessageListener<Message extends Data | Response>
(
worker: Worker,
listener: (message: MessageValue<Message>) => void
): void {
worker.on('message', listener)
}
worker: Worker,
listener: (message: MessageValue<Message>) => void
): void {
worker.on('message', listener)
}
- /** @inherit
d
oc */
+ /** @inherit
D
oc */
protected createWorker (): Worker {
return cluster.fork(this.opts.env)
}
protected createWorker (): Worker {
return cluster.fork(this.opts.env)
}
- /** @inherit
d
oc */
+ /** @inherit
D
oc */
protected afterWorkerSetup (worker: Worker): void {
protected afterWorkerSetup (worker: Worker): void {
- // Listen worker messages.
+ // Listen
to
worker messages.
this.registerWorkerMessageListener(worker, super.workerListener())
}
this.registerWorkerMessageListener(worker, super.workerListener())
}
- /** @inherit
d
oc */
+ /** @inherit
D
oc */
public get type (): PoolType {
return PoolType.FIXED
}
public get type (): PoolType {
return PoolType.FIXED
}
- /** @inheritdoc */
- public get busy (): boolean {
- return this.internalGetBusyStatus()
+ /** @inheritDoc */
+ protected get full (): boolean {
+ return this.workerNodes.length === this.numberOfWorkers
+ }
+
+ /** @inheritDoc */
+ protected get busy (): boolean {
+ return this.internalBusy()
}
}
}
}