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 2e89b3232dccbc321907b02a73b583d650ee1661..ed4f6fed2826078bfdeac466bcec7e8c4c80bef5 100644
(file)
--- a/
src/pools/cluster/fixed.ts
+++ b/
src/pools/cluster/fixed.ts
@@
-1,9
+1,9
@@
-import type { ClusterSettings, 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.
@@
-32,7
+32,7
@@
export interface ClusterPoolOptions extends PoolOptions<Worker> {
* This pool selects the workers in a round robin fashion.
*
* @typeParam Data - Type of data sent to the worker. This can only be serializable data.
* This pool selects the workers in a round robin fashion.
*
* @typeParam Data - Type of data sent to the worker. This can only be serializable data.
- * @typeParam Response - Type of
response of execution
. This can only be serializable data.
+ * @typeParam 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
*/
@@
-55,53
+55,58
@@
export class FixedClusterPool<
super(numberOfWorkers, filePath, opts)
}
super(numberOfWorkers, filePath, opts)
}
- /**
{@inheritDoc}
*/
+ /**
@inheritDoc
*/
protected setupHook (): void {
cluster.setupPrimary({ ...this.opts.settings, exec: this.filePath })
}
protected setupHook (): void {
cluster.setupPrimary({ ...this.opts.settings, exec: this.filePath })
}
- /**
{@inheritDoc}
*/
+ /**
@inheritDoc
*/
protected isMain (): boolean {
return cluster.isPrimary
}
protected isMain (): boolean {
return cluster.isPrimary
}
- /**
{@inheritDoc}
*/
- p
ublic
destroyWorker (worker: Worker): void {
+ /**
@inheritDoc
*/
+ p
rotected
destroyWorker (worker: Worker): void {
this.sendToWorker(worker, { kill: 1 })
worker.kill()
}
this.sendToWorker(worker, { kill: 1 })
worker.kill()
}
- /**
{@inheritDoc}
*/
+ /**
@inheritDoc
*/
protected sendToWorker (worker: Worker, message: MessageValue<Data>): void {
worker.send(message)
}
protected sendToWorker (worker: Worker, message: MessageValue<Data>): void {
worker.send(message)
}
- /**
{@inheritDoc}
*/
- p
ublic
registerWorkerMessageListener<Message extends Data | Response>(
+ /**
@inheritDoc
*/
+ 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)
}
- /**
{@inheritDoc}
*/
+ /**
@inheritDoc
*/
protected createWorker (): Worker {
return cluster.fork(this.opts.env)
}
protected createWorker (): Worker {
return cluster.fork(this.opts.env)
}
- /**
{@inheritDoc}
*/
+ /**
@inheritDoc
*/
protected afterWorkerSetup (worker: Worker): void {
// Listen to worker messages.
this.registerWorkerMessageListener(worker, super.workerListener())
}
protected afterWorkerSetup (worker: Worker): void {
// Listen to worker messages.
this.registerWorkerMessageListener(worker, super.workerListener())
}
- /**
{@inheritDoc}
*/
+ /**
@inheritDoc
*/
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()
}
}
}
}