fix: patch knex

Signed-off-by: Ricardo Arturo Cabral Mejía <me@ricardocabral.io>
This commit is contained in:
Ricardo Arturo Cabral Mejía 2023-01-27 22:06:26 -05:00
parent b0adba6abc
commit ad7ab69d36
2 changed files with 14 additions and 16 deletions

View File

@ -3,20 +3,20 @@ import 'pg-query-stream'
import knex, { Knex } from 'knex'
import { createLogger } from '../factories/logger-factory'
knex.Client.prototype.releaseConnection = function (connection) {
//debug('releasing connection to pool: %s', connection.__knexUid);
console.log('releasing connection to pool')
const didRelease = this.pool.release(connection)
((knex) => {
knex.Client.prototype.releaseConnection = function (connection) {
const released = this.pool.release(connection)
if (!didRelease) {
console.log('pool refused connection')
//debug('pool refused connection: %s', connection.__knexUid);
if (released) {
console.log(`${this.config.tag} conneciton pool: ${this.pool.numUsed()} used / ${this.pool.numFree()} free / ${this.pool.numPendingAcquires()} pending`)
}
return Promise.resolve()
}
return Promise.resolve()
}
})(knex)
const getMasterConfig = (): Knex.Config => ({
tag: 'master',
client: 'pg',
connection: {
host: process.env.DB_HOST,
@ -37,9 +37,10 @@ const getMasterConfig = (): Knex.Config => ({
acquireConnectionTimeout: process.env.DB_ACQUIRE_CONNECTION_TIMEOUT
? Number(process.env.DB_ACQUIRE_CONNECTION_TIMEOUT)
: 60000,
})
} as any)
const getReadReplicaConfig = (): Knex.Config => ({
tag: 'read-replica',
client: 'pg',
connection: {
host: process.env.RR_DB_HOST,
@ -57,10 +58,7 @@ const getReadReplicaConfig = (): Knex.Config => ({
? Number(process.env.RR_DB_ACQUIRE_CONNECTION_TIMEOUT)
: 60000,
},
acquireConnectionTimeout: process.env.RR_DB_ACQUIRE_CONNECTION_TIMEOUT
? Number(process.env.RR_DB_ACQUIRE_CONNECTION_TIMEOUT)
: 60000,
})
} as any)
let writeClient: Knex

View File

@ -71,7 +71,7 @@ export class SubscribeMessageHandler implements IMessageHandler, IAbortable {
)
} catch (error) {
if (error instanceof Error && error.name === 'AbortError') {
debug('subscription aborted: %o', error)
debug('subscription %s aborted: %o', subscriptionId, error)
findEvents.destroy()
} else {
debug('error streaming events: %o', error)