const workerNodeKey = this.chooseWorkerNode(name)
const task: Task<Data> = {
name: name ?? DEFAULT_TASK_NAME,
-
data: data ?? ({} as Data),
priority: this.getWorkerNodeTaskFunctionPriority(workerNodeKey, name),
strategy: this.getWorkerNodeTaskFunctionWorkerChoiceStrategy(
/**
* Starts the minimum number of workers.
- * @param initWorkerNodeUsage
+ * @param initWorkerNodeUsage - Whether to initialize the worker node usage or not. @defaultValue false
*/
private startMinimumNumberOfWorkers (initWorkerNodeUsage = false): void {
this.startingMinimumNumberOfWorkers = true
message: MessageValue<Response>
): void {
let needWorkerChoiceStrategiesUpdate = false
-
if (this.workerNodes[workerNodeKey]?.usage != null) {
const workerUsage = this.workerNodes[workerNodeKey].usage
updateTaskStatisticsWorkerUsage(workerUsage, message)
) {
this.redistributeQueuedTasks(this.workerNodes.indexOf(workerNode))
}
-
workerNode?.terminate().catch((error: unknown) => {
this.emitter?.emit(PoolEvents.error, error)
})
taskName: string
): void {
const workerNode = this.workerNodes[workerNodeKey]
-
if (workerNode?.usage != null) {
++workerNode.usage.tasks.stolen
}
previousTaskName?: string
): void {
const workerNode = this.workerNodes[workerNodeKey]
-
if (workerNode?.usage != null) {
++workerNode.usage.tasks.sequentiallyStolen
}
taskName: string
): void {
const workerNode = this.workerNodes[workerNodeKey]
-
if (workerNode?.usage != null) {
workerNode.usage.tasks.sequentiallyStolen = 0
}
/**
* This method is the message listener registered on each worker.
- * @param message
+ * @param message - The message received from the worker.
*/
protected readonly workerMessageListener = (
message: MessageValue<Response>
/**
* Updates the worker node key in the active worker choice strategies in the context internals.
- * @param workerNodeKey
+ * @param workerNodeKey - The worker node key.
* @returns `true` if the update is successful, `false` otherwise.
*/
public update (workerNodeKey: number): boolean {
/**
* Adds a worker choice strategy to the context.
* @param workerChoiceStrategy - The worker choice strategy to add.
- * @param pool
+ * @param pool - The pool instance.
* @param opts - The worker choice strategy options.
* @returns The worker choice strategies.
*/