X-Git-Url: https://git.squeep.com/?a=blobdiff_plain;f=src%2Fdb%2Fpostgres%2Flistener.js;h=1ce3b3b3a99616ac8a645bcd3b7686ffa8dcc967;hb=8cd88ab4087a7fab2ccd6e231c64d7f0f1299f26;hp=6ad387aa49ea2e11a91e29a6de60094eea4024aa;hpb=3fae9b64c5c70ad52376558caa71db99778541b0;p=websub-hub diff --git a/src/db/postgres/listener.js b/src/db/postgres/listener.js index 6ad387a..1ce3b3b 100644 --- a/src/db/postgres/listener.js +++ b/src/db/postgres/listener.js @@ -23,7 +23,10 @@ class PostgresListener { this.logger = logger; this.db = db; - this.options = Object.assign({}, defaultOptions, options); + this.options = { + ...defaultOptions, + ...options, + }; this.notificationEventName = 'notification'; this.connection = null; @@ -54,7 +57,7 @@ class PostgresListener { delete this.reconnectPending; } if (this.connection) { - this.connection.client.removeListener(this.notificationEventName, this.onNotificationBound); + this.connection.client.removeListener(this.notificationEventName, this._onNotificationBound); this.connection.done(); this.connection = null; await this.options.connectionLostCallback(); @@ -83,7 +86,7 @@ class PostgresListener { /** * Notify callback. - * @param {Object} data + * @param {object} data listener notification */ async _onNotification(data) { const _scope = _fileScope('_onNotification'); @@ -98,15 +101,15 @@ class PostgresListener { /** * Notify callback and attempt to reconnect. - * @param {*} error - * @param {*} event + * @param {*} error error + * @param {*} event event */ async _onConnectionLost(error, event) { const _scope = _fileScope('_onConnectionLost'); this.logger.error(_scope, 'listener connection lost', { error, event }); this.connection = null; try { - event.client.removeListener(this.notificationEventName, this.onNotificationBound); + event.client.removeListener(this.notificationEventName, this._onNotificationBound); } catch (e) { this.logger.error(_scope, 'failed to remove listener', { error: e }); // That's okay, it was probably just gone anyhow. @@ -122,8 +125,8 @@ class PostgresListener { /** * Schedule an attempt to establish a connection. - * @param {Number} delay - * @param {Number} retriesRemaining + * @param {number} delay reconnect delay + * @param {number} retriesRemaining retry countdown */ async _reconnect(delay, retriesRemaining) { const _scope = _fileScope('_reconnect');