Make max tries configurable

This commit is contained in:
Ajay 2022-08-20 17:57:40 -04:00
parent 47a6a13bdb
commit 6be2f96f26
3 changed files with 7 additions and 5 deletions

View file

@ -81,7 +81,8 @@ addDefaults(config, {
password: "", password: "",
port: 5432, port: 5432,
max: 10, max: 10,
idleTimeoutMillis: 10000 idleTimeoutMillis: 10000,
maxTries: 3
}, },
postgresReadOnly: { postgresReadOnly: {
enabled: false, enabled: false,
@ -92,7 +93,8 @@ addDefaults(config, {
port: 5432, port: 5432,
readTimeout: 250, readTimeout: 250,
max: 10, max: 10,
idleTimeoutMillis: 10000 idleTimeoutMillis: 10000,
maxTries: 3
}, },
dumpDatabase: { dumpDatabase: {
enabled: false, enabled: false,

View file

@ -33,8 +33,6 @@ export class Postgres implements IDatabase {
private poolRead: Pool; private poolRead: Pool;
private lastPoolReadFail = 0; private lastPoolReadFail = 0;
private maxTries = 3;
constructor(private config: DatabaseConfig) {} constructor(private config: DatabaseConfig) {}
async init(): Promise<void> { async init(): Promise<void> {
@ -141,7 +139,8 @@ export class Postgres implements IDatabase {
Logger.error(`prepare (postgres) try ${tries}: ${err}`); Logger.error(`prepare (postgres) try ${tries}: ${err}`);
} }
} while (this.isReadQuery(type) && tries < this.maxTries); } while (this.isReadQuery(type) && tries < (lastPool === this.pool
? this.config.postgres.maxTries : this.config.postgresReadOnly.maxTries));
} }
private getPool(type: string, options: QueryOption): Pool { private getPool(type: string, options: QueryOption): Pool {

View file

@ -8,6 +8,7 @@ interface RedisConfig extends redis.RedisClientOptions {
export interface CustomPostgresConfig extends PoolConfig { export interface CustomPostgresConfig extends PoolConfig {
enabled: boolean; enabled: boolean;
maxTries: number;
} }
export interface CustomPostgresReadOnlyConfig extends CustomPostgresConfig { export interface CustomPostgresReadOnlyConfig extends CustomPostgresConfig {