mirror of https://github.com/calzoneman/sync.git
Make redis announcement channel configurable
Finally fix the bug where announcements bleed across beta & live due to sharing a redis pubsub channel.
This commit is contained in:
parent
964feb7243
commit
ffde151ebd
|
@ -3,12 +3,12 @@ import uuid from 'uuid';
|
||||||
const LOGGER = require('@calzoneman/jsli')('announcementrefresher');
|
const LOGGER = require('@calzoneman/jsli')('announcementrefresher');
|
||||||
|
|
||||||
var SERVER;
|
var SERVER;
|
||||||
const SERVER_ANNOUNCEMENTS = 'serverAnnouncements';
|
|
||||||
|
|
||||||
class AnnouncementRefresher {
|
class AnnouncementRefresher {
|
||||||
constructor(pubClient, subClient) {
|
constructor(pubClient, subClient, channel) {
|
||||||
this.pubClient = pubClient;
|
this.pubClient = pubClient;
|
||||||
this.subClient = subClient;
|
this.subClient = subClient;
|
||||||
|
this.channel = channel;
|
||||||
this.uuid = uuid.v4();
|
this.uuid = uuid.v4();
|
||||||
process.nextTick(this.init.bind(this));
|
process.nextTick(this.init.bind(this));
|
||||||
}
|
}
|
||||||
|
@ -19,12 +19,13 @@ class AnnouncementRefresher {
|
||||||
|
|
||||||
this.subClient.once('ready', () => {
|
this.subClient.once('ready', () => {
|
||||||
this.subClient.on('message', this.handleMessage.bind(this));
|
this.subClient.on('message', this.handleMessage.bind(this));
|
||||||
this.subClient.subscribe(SERVER_ANNOUNCEMENTS);
|
this.subClient.subscribe(this.channel);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
handleMessage(channel, message) {
|
handleMessage(channel, message) {
|
||||||
if (channel !== SERVER_ANNOUNCEMENTS) {
|
if (channel !== this.channel) {
|
||||||
|
LOGGER.warn('Unexpected message from channel "%s"', channel);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,7 +50,7 @@ class AnnouncementRefresher {
|
||||||
data: data,
|
data: data,
|
||||||
partitionID: this.uuid
|
partitionID: this.uuid
|
||||||
});
|
});
|
||||||
this.pubClient.publish(SERVER_ANNOUNCEMENTS, message);
|
this.pubClient.publish(this.channel, message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,10 @@ class PartitionConfig {
|
||||||
getPartitionMapKey() {
|
getPartitionMapKey() {
|
||||||
return this.config.redis.partitionMapKey;
|
return this.config.redis.partitionMapKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getAnnouncementChannel() {
|
||||||
|
return this.config.redis.announcementChannel || 'serverAnnouncements';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export { PartitionConfig };
|
export { PartitionConfig };
|
||||||
|
|
|
@ -97,7 +97,8 @@ class PartitionModule {
|
||||||
const provider = this.getRedisClientProvider();
|
const provider = this.getRedisClientProvider();
|
||||||
this.announcementRefresher = new AnnouncementRefresher(
|
this.announcementRefresher = new AnnouncementRefresher(
|
||||||
provider.get(),
|
provider.get(),
|
||||||
provider.get()
|
provider.get(),
|
||||||
|
this.partitionConfig.getAnnouncementChannel()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue