1
0
Fork 0
mirror of https://github.com/FrankerFaceZ/FrankerFaceZ.git synced 2025-06-27 21:05:53 +00:00
* Fixed: Remove debug logging.
* Experiment Changed: Tweak the MQTT pub/sub client to handle subscription failures better.
This commit is contained in:
SirStendec 2023-11-05 19:48:38 -05:00
parent a7e131070e
commit 5046088bf7
4 changed files with 27 additions and 6 deletions

View file

@ -1,7 +1,7 @@
{
"name": "frankerfacez",
"author": "Dan Salvato LLC",
"version": "4.59.0",
"version": "4.59.1",
"description": "FrankerFaceZ is a Twitch enhancement suite.",
"private": true,
"license": "Apache-2.0",

View file

@ -140,6 +140,7 @@ export default class PubSub extends Module {
const PubSubClient = await this.loadPubSubClient();
const client = this._client = new PubSubClient(cluster, {
logger: this.log.get('client'),
user: user?.id ? {
provider: 'twitch',
id: user.id

View file

@ -281,8 +281,8 @@ export class EventEmitter {
if ( ret instanceof Promise ) {
if ( (args[0] instanceof FFZWaitableEvent) )
args[0].waitFor(ret);
else if ( this.log )
this.log.error(`handler for event "${event}" returned a Promise but the event is not an FFZWaitableEvent`);
/*else if ( this.log )
this.log.debug(`handler for event "${event}" returned a Promise but the event is not an FFZWaitableEvent`);*/
}
if ( (args[0] instanceof FFZEvent && args[0].propagationStopped) || ret === StopPropagation )

View file

@ -590,14 +590,34 @@ export default class PubSubClient extends EventEmitter {
return Promise.resolve();
return this._client.subscribe({topicFilter: topics })
.catch(() => {
.then(() => {
// Success. Reset the subscribe failures count.
this._sub_failures = 0;
})
.catch(msg => {
// TODO: Check the reason why.
if ( this.logger )
this.logger.debug('Subscribe failure for topics:', batch.join(', '), ' reason:', msg);
// If there was an error, we did NOT subscribe.
for(const topic of batch)
this._live_topics.delete(topic);
// See if we have more work.
if ( this._live_topics.size >= this._active_topics.size )
return;
// Call sendSubscribes again after a bit.
if ( this._live_topics.size != this._active_topics.size )
return sleep(2000).then(() => this._sendSubscribes());
this._sub_failures = (this._sub_failures || 0) + 1;
let delay = (this._sub_failures * Math.floor(Math.random() * 10) + 2) * 1000;
if ( delay > 60000 )
delay = (Math.floor(Math.random() * 60) + 30) * 1000;
if ( delay <= 2000 )
delay = 2000;
return sleep(delay).then(() => this._sendSubscribes());
});
}