Add HTTP cancellation support to sync runner
This commit is contained in:
parent
25e34b7b99
commit
ca7217cff7
2 changed files with 15 additions and 2 deletions
|
@ -37,6 +37,7 @@ Zotero.Sync.APIClient = function (options) {
|
|||
this.apiKey = options.apiKey;
|
||||
this.caller = options.caller;
|
||||
this.debugUploadPolicy = Zotero.Prefs.get('sync.debugUploadPolicy');
|
||||
this.cancellerReceiver = options.cancellerReceiver;
|
||||
|
||||
this.rateDelayIntervals = [30, 60, 300];
|
||||
this.rateDelayPosition = 0;
|
||||
|
@ -647,6 +648,7 @@ Zotero.Sync.APIClient.prototype = {
|
|||
&& Zotero.Prefs.get('sync.server.compressData')) {
|
||||
opts.compressBody = true;
|
||||
}
|
||||
opts.cancellerReceiver = this.cancellerReceiver;
|
||||
|
||||
var tries = 0;
|
||||
while (true) {
|
||||
|
|
|
@ -75,6 +75,7 @@ Zotero.Sync.Runner_Module = function (options = {}) {
|
|||
var _firstInSession = true;
|
||||
var _syncInProgress = false;
|
||||
var _stopping = false;
|
||||
var _canceller;
|
||||
var _manualSyncRequired = false; // TODO: make public?
|
||||
|
||||
var _currentEngine = null;
|
||||
|
@ -92,7 +93,8 @@ Zotero.Sync.Runner_Module = function (options = {}) {
|
|||
baseURL: this.baseURL,
|
||||
apiVersion: this.apiVersion,
|
||||
apiKey: options.apiKey,
|
||||
caller: this.caller
|
||||
caller: this.caller,
|
||||
cancellerReceiver: _cancellerReceiver,
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -282,7 +284,8 @@ Zotero.Sync.Runner_Module = function (options = {}) {
|
|||
_errors = [];
|
||||
}
|
||||
|
||||
if (e instanceof Zotero.Sync.UserCancelledException) {
|
||||
if (e instanceof Zotero.Sync.UserCancelledException
|
||||
|| e instanceof Zotero.HTTP.CancelledException) {
|
||||
Zotero.debug("Sync was cancelled");
|
||||
}
|
||||
else if (options.onError) {
|
||||
|
@ -867,6 +870,9 @@ Zotero.Sync.Runner_Module = function (options = {}) {
|
|||
if (_currentEngine) {
|
||||
_currentEngine.stop();
|
||||
}
|
||||
if (_canceller) {
|
||||
_canceller();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -1571,4 +1577,9 @@ Zotero.Sync.Runner_Module = function (options = {}) {
|
|||
throw new Zotero.Sync.UserCancelledException;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function _cancellerReceiver(canceller) {
|
||||
_canceller = canceller;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue