Skip to content

Commit a505659

Browse files
committed
chore: log conn pool every min
Signed-off-by: Ricardo Arturo Cabral Mejía <[email protected]>
1 parent 199fa55 commit a505659

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/database/client.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ import knex, { Knex } from 'knex'
44
import { createLogger } from '../factories/logger-factory'
55

66
((knex) => {
7-
const counters = {}
7+
const lastUpdate = {}
88
knex.Client.prototype.releaseConnection = function (connection) {
99
const released = this.pool.release(connection)
1010

1111
if (released) {
12-
counters[this.config.tag] = (counters[this.config.tag] ?? 0) + 1
13-
if (counters[this.config.tag] % 10 === 0) {
12+
const now = new Date().getTime()
13+
lastUpdate[this.config.tag] = lastUpdate[this.config.tag] ?? now
14+
if (now - lastUpdate[this.config.tag] >= 60000) {
15+
lastUpdate[this.config.tag] = now
1416
console.log(`${this.config.tag} connection pool: ${this.pool.numUsed()} used / ${this.pool.numFree()} free / ${this.pool.numPendingAcquires()} pending`)
1517
}
1618
}

0 commit comments

Comments
 (0)