mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-09 13:07:02 +03:00
Add option to disable fallback after failure
This commit is contained in:
@@ -88,7 +88,8 @@ addDefaults(config, {
|
|||||||
readTimeout: 250,
|
readTimeout: 250,
|
||||||
max: 10,
|
max: 10,
|
||||||
idleTimeoutMillis: 10000,
|
idleTimeoutMillis: 10000,
|
||||||
maxTries: 3
|
maxTries: 3,
|
||||||
|
fallbackOnFail: true
|
||||||
},
|
},
|
||||||
dumpDatabase: {
|
dumpDatabase: {
|
||||||
enabled: false,
|
enabled: false,
|
||||||
|
|||||||
@@ -148,8 +148,10 @@ export class Postgres implements IDatabase {
|
|||||||
|
|
||||||
private getPool(type: string, options: QueryOption): Pool {
|
private getPool(type: string, options: QueryOption): Pool {
|
||||||
const readAvailable = this.poolRead && options.useReplica && this.isReadQuery(type);
|
const readAvailable = this.poolRead && options.useReplica && this.isReadQuery(type);
|
||||||
const ignroreReadDueToFailure = this.lastPoolReadFail > Date.now() - 1000 * 30;
|
const ignroreReadDueToFailure = this.config.postgresReadOnly.fallbackOnFail
|
||||||
const readDueToFailure = this.lastPoolFail > Date.now() - 1000 * 30;
|
&& this.lastPoolReadFail > Date.now() - 1000 * 30;
|
||||||
|
const readDueToFailure = this.config.postgresReadOnly.fallbackOnFail
|
||||||
|
&& this.lastPoolFail > Date.now() - 1000 * 30;
|
||||||
if (readAvailable && !ignroreReadDueToFailure && (options.forceReplica || readDueToFailure ||
|
if (readAvailable && !ignroreReadDueToFailure && (options.forceReplica || readDueToFailure ||
|
||||||
Math.random() > 1 / (this.config.postgresReadOnly.weight + 1))) {
|
Math.random() > 1 / (this.config.postgresReadOnly.weight + 1))) {
|
||||||
return this.poolRead;
|
return this.poolRead;
|
||||||
|
|||||||
Reference in New Issue
Block a user