feat(Postgres Node): Options keepAlive and keepAliveInitialDelayMillis (#9067)

This commit is contained in:
Michael Kret
2024-04-09 18:41:51 +03:00
committed by GitHub
parent c2f4d7d796
commit 58518b684b
16 changed files with 136 additions and 31 deletions

View File

@@ -87,6 +87,10 @@ export async function pgTriggerFunction(
export async function initDB(this: ITriggerFunctions | ILoadOptionsFunctions) {
const credentials = await this.getCredentials('postgres');
const options = this.getNodeParameter('options', {}) as {
connectionTimeout?: number;
delayClosingIdleConnection?: number;
};
const pgp = pgPromise({
// prevent spam in console "WARNING: Creating a duplicate database object for the same connection."
noWarnings: true,
@@ -97,8 +101,17 @@ export async function initDB(this: ITriggerFunctions | ILoadOptionsFunctions) {
database: credentials.database as string,
user: credentials.user as string,
password: credentials.password as string,
keepAlive: true,
};
if (options.connectionTimeout) {
config.connectionTimeoutMillis = options.connectionTimeout * 1000;
}
if (options.delayClosingIdleConnection) {
config.keepAliveInitialDelayMillis = options.delayClosingIdleConnection * 1000;
}
if (credentials.allowUnauthorizedCerts === true) {
config.ssl = {
rejectUnauthorized: false,