Fix fail calculation

This commit is contained in:
Ajay 2022-06-25 12:30:16 -04:00
parent e615d7c032
commit 86e61c778c

View file

@ -111,8 +111,8 @@ export class Postgres implements IDatabase {
private getClient(type: string): Promise<PoolClient> {
const readAvailable = this.poolRead && (type === "get" || type === "all");
const ignroreReadDueToFailure = this.lastPoolReadFail < Date.now() - 1000 * 30;
const readDueToFailure = this.lastPoolFail < Date.now() - 1000 * 30;
const ignroreReadDueToFailure = this.lastPoolReadFail > Date.now() - 1000 * 30;
const readDueToFailure = this.lastPoolFail > Date.now() - 1000 * 30;
if (readAvailable && !ignroreReadDueToFailure && (readDueToFailure ||
Math.random() > 1 / (this.config.postgresReadOnly.weight + 1))) {
return this.poolRead.connect();