From e74f3d6081cb8c7617ffa212938bcd15383ba86c Mon Sep 17 00:00:00 2001 From: Simon Martin Date: Wed, 19 Aug 2020 18:30:18 +0200 Subject: [PATCH 1/3] force draining pools --- index.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/index.js b/index.js index fc184fb..99c12d3 100644 --- a/index.js +++ b/index.js @@ -97,6 +97,15 @@ module.exports = class RedisPool extends EventEmitter { } } + /** + * Closing all connection pools + * + * https://github.com/coopernurse/node-pool/blob/v3.7.1/README.md#draining + */ + async drain () { + await Promise.all(Object.values(this.pools).map(p => p.drain().then(() => p.clear())) ) + } + _addCommands () { if (this.options.commands.length) { this.options.commands.forEach(newCommand => redis.add_command(newCommand)); From de8ee1c500b42bb0ef1472a29c9d75d24f99a942 Mon Sep 17 00:00:00 2001 From: Simon Martin Date: Thu, 20 Aug 2020 13:57:58 +0200 Subject: [PATCH 2/3] clearInterval --- index.js | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/index.js b/index.js index 99c12d3..89d2c17 100644 --- a/index.js +++ b/index.js @@ -43,15 +43,15 @@ module.exports = class RedisPool extends EventEmitter { this.logger = logger; this._addCommands(); - this._emitStatus(); + this._statusInterval = this._emitStatus(); } /** - * Acquire Redis client - * - * @param {String|Number} database redis database name - * @returns {Promise} with the Redis client - */ + * Acquire Redis client + * + * @param {String|Number} database redis database name + * @returns {Promise} with the Redis client + */ async acquire (database) { let pool = this.pools[database]; if (!pool) { @@ -80,11 +80,11 @@ module.exports = class RedisPool extends EventEmitter { } /** - * Release resource. - * - * @param {String|Number} database redis database name - * @param {Object} resource resource object to release - */ + * Release resource. + * + * @param {String|Number} database redis database name + * @param {Object} resource resource object to release + */ async release (database, resource) { if (this.options.unwatchOnRelease) { resource.UNWATCH(); @@ -99,11 +99,13 @@ module.exports = class RedisPool extends EventEmitter { /** * Closing all connection pools - * - * https://github.com/coopernurse/node-pool/blob/v3.7.1/README.md#draining + * */ - async drain () { - await Promise.all(Object.values(this.pools).map(p => p.drain().then(() => p.clear())) ) + async destroy () { + clearInterval(this._statusInterval) + + // https://github.com/coopernurse/node-pool/blob/v3.7.1/README.md#draining + return await Promise.all(Object.values(this.pools).map(p => p.drain().then(() => p.clear())) ) } _addCommands () { @@ -113,7 +115,7 @@ module.exports = class RedisPool extends EventEmitter { } _emitStatus () { - setInterval(() => { + return setInterval(() => { for (const [poolKey, pool] of Object.entries(this.pools)) { this.emit('status', { name: this.options.name, From e0a3067282bb8f55fa28defd389e2b274b1f16c8 Mon Sep 17 00:00:00 2001 From: Simon Martin Date: Thu, 20 Aug 2020 14:02:29 +0200 Subject: [PATCH 3/3] version 0.8.1 --- NEWS.md | 5 +++++ index.js | 3 +-- package-lock.json | 2 +- package.json | 2 +- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/NEWS.md b/NEWS.md index 9f8ef01..2ed1f5c 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,8 @@ +# 0.8.1 (2020-08-20) + +### Added + - New `destroy` method in order to drain all pools and clear internal interval + # 0.8.0 (2020-05-13) ### Breaking changes diff --git a/index.js b/index.js index 89d2c17..d7e536d 100644 --- a/index.js +++ b/index.js @@ -99,11 +99,10 @@ module.exports = class RedisPool extends EventEmitter { /** * Closing all connection pools - * */ async destroy () { clearInterval(this._statusInterval) - + // https://github.com/coopernurse/node-pool/blob/v3.7.1/README.md#draining return await Promise.all(Object.values(this.pools).map(p => p.drain().then(() => p.clear())) ) } diff --git a/package-lock.json b/package-lock.json index aa3ff4a..3b8a7a9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "redis-mpool", - "version": "0.8.0", + "version": "0.8.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index d026074..1597b28 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "redis-mpool", - "version": "0.8.0", + "version": "0.8.1", "main": "./index.js", "description": "Provides db pools for redis", "url": "https://github.com/cartodb/node-redis-mpool",