From d63d3be337008b24e8669a8912f82ae426dd9b2e Mon Sep 17 00:00:00 2001 From: aardizio Date: Mon, 15 Feb 2021 19:37:12 +0100 Subject: [PATCH] Implement PR reviews --- CHANGELOG.md | 4 +++- src/pools/abstract-pool.ts | 16 ++++++++-------- src/pools/cluster/dynamic.ts | 4 +++- src/pools/thread/dynamic.ts | 6 +++--- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 12fd3608..67a447c3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [2.0.0] - not released yet ### Bug fixes - - Now a thread/process is not delete when the task submitted take more time than maxInactiveTime configured( issue #70) + +- Now a thread/process is not delete when the task submitted take more time than maxInactiveTime configured (issue #70) + ### Breaking Changes We changed some internal structures, but you shouldn't be too affected by them as these are internal changes. diff --git a/src/pools/abstract-pool.ts b/src/pools/abstract-pool.ts index 879e3e4f..0685f998 100644 --- a/src/pools/abstract-pool.ts +++ b/src/pools/abstract-pool.ts @@ -190,23 +190,23 @@ export abstract class AbstractPool< * @param worker Workers whose tasks are increased. */ protected increaseWorkersTask (worker: Worker): void { - const numberOfTasksTheWorkerHas = this.tasks.get(worker) - if (numberOfTasksTheWorkerHas !== undefined) { - this.tasks.set(worker, numberOfTasksTheWorkerHas + 1) + const numberOfTasksInProgress = this.tasks.get(worker) + if (numberOfTasksInProgress !== undefined) { + this.tasks.set(worker, numberOfTasksInProgress + 1) } else { throw Error('Worker could not be found in tasks map') } } /** - * Increase the number of tasks that the given workers has done. + * Decrease the number of tasks that the given workers has done. * - * @param worker Workers whose tasks are increased. + * @param worker Workers whose tasks are decreased. */ protected decreaseWorkersTasks (worker: Worker): void { - const numberOfTasksTheWorkerHas = this.tasks.get(worker) - if (numberOfTasksTheWorkerHas !== undefined) { - this.tasks.set(worker, numberOfTasksTheWorkerHas - 1) + const numberOfTasksInProgress = this.tasks.get(worker) + if (numberOfTasksInProgress !== undefined) { + this.tasks.set(worker, numberOfTasksInProgress - 1) } else { throw Error('Worker could not be found in tasks map') } diff --git a/src/pools/cluster/dynamic.ts b/src/pools/cluster/dynamic.ts index f6c70126..5eba843a 100644 --- a/src/pools/cluster/dynamic.ts +++ b/src/pools/cluster/dynamic.ts @@ -62,7 +62,9 @@ export class DynamicClusterPool< const worker = this.createAndSetupWorker() this.registerWorkerMessageListener(worker, message => { const tasksInProgress = this.tasks.get(worker) - if (message.kill && !tasksInProgress) { + if (message.kill && tasksInProgress === 0) { + // Kill received from the worker, means that no new tasks are submitted to that worker for a while ( > maxInactiveTime) + // To handle the case of a long-running task we will check if there is any active task this.sendToWorker(worker, { kill: 1 }) void this.destroyWorker(worker) } diff --git a/src/pools/thread/dynamic.ts b/src/pools/thread/dynamic.ts index 74013f2b..26d81d2f 100644 --- a/src/pools/thread/dynamic.ts +++ b/src/pools/thread/dynamic.ts @@ -62,9 +62,9 @@ export class DynamicThreadPool< const worker = this.createAndSetupWorker() this.registerWorkerMessageListener(worker, message => { const tasksInProgress = this.tasks.get(worker) - if (message.kill && !tasksInProgress) { - // Kill received from the worker, means that no new tasks are submitted to that worker for a while( > maxInactiveTime) - // To handle the case of a long-running task we will check if the there is any active task + if (message.kill && tasksInProgress === 0) { + // Kill received from the worker, means that no new tasks are submitted to that worker for a while ( > maxInactiveTime) + // To handle the case of a long-running task we will check if there is any active task this.sendToWorker(worker, { kill: 1 }) void this.destroyWorker(worker) } -- 2.34.1