CommentController: Delay polling on error

Use exponential backoff.

Bug: T362814
Change-Id: I436a700de3b89abbfa1f991bcf6dc7aa52008cbd
This commit is contained in:
Bartosz Dziewoński 2024-04-26 04:35:12 +02:00
parent b8a28d6cfc
commit 1bfd97580e

View file

@ -228,7 +228,9 @@ CommentController.prototype.onVisibilityChange = function () {
}
};
CommentController.prototype.startPoll = function () {
CommentController.prototype.startPoll = function ( nextDelay ) {
nextDelay = nextDelay || 5000;
var threadItemId = this.threadItem.id;
var subscribableHeadingId = this.threadItem.getSubscribableHeading().id;
@ -268,11 +270,18 @@ CommentController.prototype.startPoll = function () {
}
this.oldId = result.torevid;
nextDelay = 5000;
}, () => {
// Wait longer next time in case of error
nextDelay = nextDelay * 1.5;
} ).always( () => {
if ( this.isTornDown ) {
return;
}
this.pollTimeout = setTimeout( this.startPoll.bind( this ), 5000 );
// Stop polling after too many errors
if ( nextDelay < 1000 * 60 * 60 ) {
this.pollTimeout = setTimeout( this.startPoll.bind( this, nextDelay ), nextDelay );
}
} );
};