mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
fix: don't publish before pubClient is connected
This commit is contained in:
@@ -10,7 +10,7 @@ let channelName;
|
||||
const PubSub = function () {
|
||||
const self = this;
|
||||
channelName = `db:${nconf.get('redis:database')}:pubsub_channel`;
|
||||
|
||||
self.queue = [];
|
||||
connection.connect().then((client) => {
|
||||
self.subClient = client;
|
||||
self.subClient.subscribe(channelName);
|
||||
@@ -30,13 +30,20 @@ const PubSub = function () {
|
||||
|
||||
connection.connect().then((client) => {
|
||||
self.pubClient = client;
|
||||
self.queue.forEach(payload => client.publish(channelName, payload));
|
||||
self.queue.length = 0;
|
||||
});
|
||||
};
|
||||
|
||||
util.inherits(PubSub, EventEmitter);
|
||||
|
||||
PubSub.prototype.publish = function (event, data) {
|
||||
this.pubClient.publish(channelName, JSON.stringify({ event: event, data: data }));
|
||||
const payload = JSON.stringify({ event: event, data: data });
|
||||
if (this.pubClient) {
|
||||
this.pubClient.publish(channelName, payload);
|
||||
} else {
|
||||
this.queue.push(payload);
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = new PubSub();
|
||||
|
||||
Reference in New Issue
Block a user