-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #78 from MatteoGioioso/connection-filtering
Connection filtering
- Loading branch information
Showing
5 changed files
with
101 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,6 @@ | |
* This module wrap node-postgres package, more detail regarding it can be found here: | ||
* https://github.com/brianc/node-postgres | ||
* @author Matteo Gioioso <[email protected]> | ||
* @version 1.3.0 | ||
* @license MIT | ||
*/ | ||
|
||
|
@@ -46,13 +45,15 @@ ServerlessClient.prototype._getIdleProcessesListOrderByDate = async function () | |
WHERE datname = $1 | ||
AND state = 'idle' | ||
AND usename = $2 | ||
AND application_name = $4 | ||
ORDER BY state_change | ||
LIMIT $3;` | ||
|
||
const values = [ | ||
this._client.database, | ||
this._client.user, | ||
this._strategy.maxIdleConnectionsToKill | ||
this._strategy.maxIdleConnectionsToKill, | ||
this._application_name | ||
] | ||
|
||
try { | ||
|
@@ -78,6 +79,7 @@ ServerlessClient.prototype._getIdleProcessesListByMinimumTimeout = async functio | |
WHERE usename = $1 | ||
AND datname = $2 | ||
AND state = 'idle' | ||
AND application_name = $5 | ||
) | ||
SELECT pid | ||
FROM processes | ||
|
@@ -88,7 +90,8 @@ ServerlessClient.prototype._getIdleProcessesListByMinimumTimeout = async functio | |
this._client.user, | ||
this._client.database, | ||
this._strategy.minConnIdleTimeSec, | ||
this._strategy.maxIdleConnectionsToKill | ||
this._strategy.maxIdleConnectionsToKill, | ||
this._application_name | ||
] | ||
|
||
try { | ||
|
@@ -117,9 +120,10 @@ ServerlessClient.prototype._getProcessesCount = async function () { | |
SELECT COUNT(pid) | ||
FROM pg_stat_activity | ||
WHERE datname = $1 | ||
AND usename = $2;` | ||
AND usename = $2 | ||
AND application_name = $3;` | ||
|
||
const values = [this._client.database, this._client.user] | ||
const values = [this._client.database, this._client.user, this._application_name] | ||
|
||
try { | ||
const result = await this._client.query(query, values); | ||
|
@@ -147,14 +151,15 @@ ServerlessClient.prototype._killProcesses = async function (processesList) { | |
SELECT pg_terminate_backend(pid) | ||
FROM pg_stat_activity | ||
WHERE pid = ANY ($1) | ||
AND state = 'idle';` | ||
AND state = 'idle' | ||
AND application_name = $2;` | ||
|
||
const values = [pids] | ||
const values = [pids, this._application_name] | ||
|
||
try { | ||
return await this._client.query(query, values) | ||
} catch (e) { | ||
this._logger("Swallowed internal error", e.message) | ||
this._logger("Swallowed internal error: ", e.message) | ||
// Swallow the error, if this produce an error there is no need to error the function | ||
|
||
return { | ||
|
@@ -377,6 +382,9 @@ ServerlessClient.prototype.setConfig = function (config) { | |
queryRetries: 0 | ||
} | ||
|
||
this._application_name = this._config.application_name || "serverless_client" | ||
this._config.application_name = this._application_name | ||
|
||
// Prevent diffing also if client is null | ||
if (this._multipleCredentials.allowCredentialsDiffing && this._client !== null) { | ||
this._diffCredentials(prevConfig, config) | ||
|