Increase postgres read timeout and make it configurable

This commit is contained in:
Ajay
2022-08-15 17:32:07 -04:00
parent 7cb58b946a
commit c3d30b18e2
3 changed files with 4 additions and 3 deletions

View File

@@ -87,7 +87,8 @@ addDefaults(config, {
user: "", user: "",
host: "", host: "",
password: "", password: "",
port: 5432 port: 5432,
readTimeout: 250
}, },
dumpDatabase: { dumpDatabase: {
enabled: false, enabled: false,

View File

@@ -32,7 +32,6 @@ export class Postgres implements IDatabase {
private poolRead: Pool; private poolRead: Pool;
private lastPoolReadFail = 0; private lastPoolReadFail = 0;
private readTimeout = 150;
private maxTries = 3; private maxTries = 3;
@@ -116,7 +115,7 @@ export class Postgres implements IDatabase {
pendingQueries.push(savePromiseState(lastPool.query({ text: query, values: params }))); pendingQueries.push(savePromiseState(lastPool.query({ text: query, values: params })));
const currentPromises = [...pendingQueries]; const currentPromises = [...pendingQueries];
if (options.useReplica) currentPromises.push(savePromiseState(timeoutPomise(this.readTimeout))); if (options.useReplica) currentPromises.push(savePromiseState(timeoutPomise(this.config.postgresReadOnly.readTimeout)));
const queryResult = await nextFulfilment(currentPromises); const queryResult = await nextFulfilment(currentPromises);
switch (type) { switch (type) {

View File

@@ -11,6 +11,7 @@ export interface CustomPostgresConfig extends PoolConfig {
export interface CustomPostgresReadOnlyConfig extends CustomPostgresConfig { export interface CustomPostgresReadOnlyConfig extends CustomPostgresConfig {
weight: number; weight: number;
readTimeout: number;
} }
export interface SBSConfig { export interface SBSConfig {