From 8756b853fa8d842a4b66271ba20c2720b751edef Mon Sep 17 00:00:00 2001 From: Justin Wind Date: Fri, 25 Jul 2025 11:05:22 -0700 Subject: [PATCH] do not log postgres-listener pings --- lib/postgres-listener.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/postgres-listener.js b/lib/postgres-listener.js index 9810eed..bc3478f 100644 --- a/lib/postgres-listener.js +++ b/lib/postgres-listener.js @@ -29,10 +29,21 @@ const defaultOptions = { reconnectTimes: -1, // infinite retries by default }; +/** + * @typedef {import('pg-promise')} PGPromise + */ + /** * Create a robust connection which listens to a notification channel. */ class PostgresListener { + static PingPayload = 'ping'; + + /** + * @param {*} logger logger + * @param {PGPromise.Database} db db + * @param {*} options options + */ constructor(logger, db, options) { this.logger = logger; this.db = db; @@ -92,7 +103,7 @@ class PostgresListener { this.nextPingTimeout = setTimeout(async () => { try { if (this.connection) { - await this.connection.none('NOTIFY $(channel:name), $(payload)', { channel: this.options.channel, payload: 'ping' }); + await this.connection.none('NOTIFY $(channel:name), $(payload)', { channel: this.options.channel, payload: this.constructor.PingPayload }); } } catch (e) { this.logger.error(_scope, 'failed', { error: e }); @@ -109,13 +120,13 @@ class PostgresListener { */ async _onNotification(data) { const _scope = _fileScope('_onNotification'); - this.logger.debug(_scope, 'called', data); const { channel, payload } = data; // Ignore our own messages - if (payload === 'ping') { + if (payload === this.constructor.PingPayload) { return; } + this.logger.debug(_scope, 'called', data); await this.options.dataCallback(payload, channel); } -- 2.49.1