Santhosh has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/358931 )
Change subject: CX2: Improve the retry mechanism for save failures
......................................................................
CX2: Improve the retry mechanism for save failures
Bug: T167851
Change-Id: I0964d2399e93a4165ec950ef0a619e5d7d52cedb
---
M modules/mw.cx.TranslationController.js
1 file changed, 51 insertions(+), 13 deletions(-)
git pull
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ContentTranslation
refs/changes/31/358931/1
diff --git a/modules/mw.cx.TranslationController.js
b/modules/mw.cx.TranslationController.js
index 9323e19..7f65817 100644
--- a/modules/mw.cx.TranslationController.js
+++ b/modules/mw.cx.TranslationController.js
@@ -66,12 +66,21 @@
if ( !translationUnit ) {
return;
}
+
// Keep records keyed by section id and origin to avoid duplicates.
// When more than one changes to a single translation unit comes, only
// the last one need to consider for saving.
this.getTranslationUnitData( translationUnit ).forEach( function ( data
) {
this.saveQueue[ data.sectionId + '-' + data.origin ] = data;
}.bind( this ) );
+
+ // Last save failed, and a retry has been scheduled. Don't allow
starting new
+ // save requests to avoid overloading the servers, unless this is the
retry.
+ if ( this.failCounter > 0 ) {
+ mw.log( '[CX] Save request skipped because a retry has been
scheduled' );
+ return;
+ }
+
this.schedule();
};
@@ -93,6 +102,11 @@
this.emit( 'savestart' );
this.view.setStatusMessage( mw.msg( 'cx-save-draft-saving' ) );
if ( this.saveRequest ) {
+ mw.log( '[CX] Aborted active save request' );
+ // This causes failCounter to increase because the in-flight
request fails.
+ // The new request we do below will either reset the fail
counter on success.
+ // If it does not succeed, the retry timer that was set by the
failed request
+ // prevents further saves before the retry has completed
succesfully or given up.
this.saveRequest.abort();
}
@@ -108,21 +122,45 @@
progress: JSON.stringify( this.translation.getProgress() )
};
+ if ( this.failCounter > 0 ) {
+ mw.log( '[CX] Retring to save the translation. Failed ' +
this.failCounter + ' times so far.' );
+ }
this.saveRequest = api.postWithToken( 'csrf', params )
- .done( this.onSaveComplete.bind( this ) )
- .fail( this.onSaveFailure.bind( this ) )
- .always( function () {
- this.saveRequest = null;
- if ( this.failCounter > 5 ) {
- // If there are more than 5 save errors, stop
autosave at timer triggers.
- // It will get restarted on further translation
edits.
- // Show a bigger error message at this point.
- this.emit( 'saveerror' );
- this.onSaveFailure();
- return;
+ .done( function() {
+ this.onSaveComplete();
+
+ // Reset fail counter.
+ if ( this.failCounter > 0 ) {
+ this.failCounter = 0;
+ this.schedule = OO.ui.debounce(
this.processSaveQueue.bind( this ), 3 * 1000 );
}
- // Irrespective of success or fail, schedule next
autosave
- this.schedule();
+ }.bind( this ) ).fail( function( errorCode, details ) {
+ var delay;
+
+ mw.log.warn( '[CX] Saving Failed. Error code: ' +
errorCode + ' Details: ' + details );
+ if ( details.exception !== 'abort' ) {
+ this.onSaveFailure( errorCode, details );
+ }
+
+ this.failCounter++;
+
+ if ( this.failCounter > 5 ) {
+ // If there are more than few errors, stop
autosave at timer triggers.
+ // Show a bigger error message at this point.
+ this.view.showMessage( 'error', mw.msg(
'cx-save-draft-error' ) );
+ // This will allow any change to trigger save
again
+ this.failCounter = 0;
+ mw.log.error( '[CX] Saving failed repeatedly.
Stopping retries.' );
+ } else {
+ // Delay in seconds, failCounter is [1,5]
+ delay = 60 * this.failCounter;
+ this.schedule = OO.ui.debounce(
this.processSaveQueue.bind( this ), delay * 1000 );
+ // Trigger retry.
+ this.schedule();
+ mw.log( '[CX] Retry scheduled in ' + delay + '
minutes.' );
+ }
+ }.bind( this ) ).always( function () {
+ this.saveRequest = null;
}.bind( this ) );
};
--
To view, visit https://gerrit.wikimedia.org/r/358931
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I0964d2399e93a4165ec950ef0a619e5d7d52cedb
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ContentTranslation
Gerrit-Branch: master
Gerrit-Owner: Santhosh <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits