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

View File

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