Change: drop our retry code

This commit is contained in:
eight04 2021-12-08 21:39:36 +08:00
parent 80cea8dbcd
commit 3c5491ec62

View File

@ -11,7 +11,6 @@ const syncMan = (() => {
const SYNC_DELAY = 1; // minutes const SYNC_DELAY = 1; // minutes
const SYNC_INTERVAL = 30; // minutes const SYNC_INTERVAL = 30; // minutes
const SYNC_LOCK_RETRIES = 10; // number of retries before the error is reported for scheduled sync
const STATES = Object.freeze({ const STATES = Object.freeze({
connected: 'connected', connected: 'connected',
connecting: 'connecting', connecting: 'connecting',
@ -27,7 +26,6 @@ const syncMan = (() => {
currentDriveName: null, currentDriveName: null,
errorMessage: null, errorMessage: null,
login: false, login: false,
lockRetries: 0,
}; };
let lastError = null; let lastError = null;
let ctrl; let ctrl;
@ -44,9 +42,7 @@ const syncMan = (() => {
chrome.alarms.onAlarm.addListener(async ({name}) => { chrome.alarms.onAlarm.addListener(async ({name}) => {
if (name === 'syncNow') { if (name === 'syncNow') {
await syncMan.syncNow({isScheduled: true}); await syncMan.syncNow();
const retrying = status.lockRetries / SYNC_LOCK_RETRIES * Math.random();
schedule(SYNC_DELAY + SYNC_INTERVAL * (retrying || 1));
} }
}); });
@ -143,7 +139,7 @@ const syncMan = (() => {
emitStatusChange(); emitStatusChange();
}, },
async syncNow({isScheduled} = {}) { async syncNow() {
if (ready.then) await ready; if (ready.then) await ready;
if (!currentDrive || !status.login) { if (!currentDrive || !status.login) {
console.warn('cannot sync when disconnected'); console.warn('cannot sync when disconnected');
@ -157,16 +153,10 @@ const syncMan = (() => {
err.message = translateErrorMessage(err); err.message = translateErrorMessage(err);
status.errorMessage = err.message; status.errorMessage = err.message;
lastError = err; lastError = err;
if (isScheduled &&
err.code === 409 &&
++status.lockRetries <= SYNC_LOCK_RETRIES) {
return;
}
if (isGrantError(err)) { if (isGrantError(err)) {
status.login = false; status.login = false;
} }
} }
status.lockRetries = 0;
emitStatusChange(); emitStatusChange();
}, },
}; };
@ -209,7 +199,9 @@ const syncMan = (() => {
setState(drive, state) { setState(drive, state) {
return chromeLocal.setValue(STORAGE_KEY + drive.name, state); return chromeLocal.setValue(STORAGE_KEY + drive.name, state);
}, },
retryMaxAttempts: 0, retryMaxAttempts: 10,
retryExp: 1.2,
retryDelay: 6,
}); });
} }
@ -259,6 +251,7 @@ const syncMan = (() => {
function schedule(delay = SYNC_DELAY) { function schedule(delay = SYNC_DELAY) {
chrome.alarms.create('syncNow', { chrome.alarms.create('syncNow', {
delayInMinutes: delay, // fractional values are supported delayInMinutes: delay, // fractional values are supported
periodInMinutes: SYNC_INTERVAL,
}); });
} }