Fix: bump db-to-cloud, show detailed LockError (#1361)
* Bump db-to-cloud * Fix: bump db-to-cloud, show detailed LockError * Fix: used -> use * Change: drop our retry code
This commit is contained in:
parent
e23077a7ea
commit
7e3c6f16e9
|
@ -1669,6 +1669,14 @@
|
|||
"message": "Sync failed.\nTry to re-login in Stylus options:\nclick 'disconnect' first, then 'connect'.",
|
||||
"description": "Tooltip for the toolbar icon"
|
||||
},
|
||||
"syncErrorLock": {
|
||||
"message": "The database is already in use. The lock will expire at $TIME$",
|
||||
"placeholders": {
|
||||
"time": {
|
||||
"content": "$1"
|
||||
}
|
||||
}
|
||||
},
|
||||
"syncStorageErrorSaving": {
|
||||
"message": "The value cannot be saved. Try reducing the amount of text.",
|
||||
"description": "Displayed when trying to save an excessively big value via storage.sync API"
|
||||
|
|
|
@ -11,7 +11,6 @@ const syncMan = (() => {
|
|||
|
||||
const SYNC_DELAY = 1; // 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({
|
||||
connected: 'connected',
|
||||
connecting: 'connecting',
|
||||
|
@ -27,7 +26,6 @@ const syncMan = (() => {
|
|||
currentDriveName: null,
|
||||
errorMessage: null,
|
||||
login: false,
|
||||
lockRetries: 0,
|
||||
};
|
||||
let lastError = null;
|
||||
let ctrl;
|
||||
|
@ -44,9 +42,7 @@ const syncMan = (() => {
|
|||
|
||||
chrome.alarms.onAlarm.addListener(async ({name}) => {
|
||||
if (name === 'syncNow') {
|
||||
await syncMan.syncNow({isScheduled: true});
|
||||
const retrying = status.lockRetries / SYNC_LOCK_RETRIES * Math.random();
|
||||
schedule(SYNC_DELAY + SYNC_INTERVAL * (retrying || 1));
|
||||
await syncMan.syncNow();
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -143,7 +139,7 @@ const syncMan = (() => {
|
|||
emitStatusChange();
|
||||
},
|
||||
|
||||
async syncNow({isScheduled} = {}) {
|
||||
async syncNow() {
|
||||
if (ready.then) await ready;
|
||||
if (!currentDrive || !status.login) {
|
||||
console.warn('cannot sync when disconnected');
|
||||
|
@ -154,18 +150,13 @@ const syncMan = (() => {
|
|||
status.errorMessage = null;
|
||||
lastError = null;
|
||||
} catch (err) {
|
||||
err.message = translateErrorMessage(err);
|
||||
status.errorMessage = err.message;
|
||||
lastError = err;
|
||||
if (isScheduled &&
|
||||
err.code === 409 &&
|
||||
++status.lockRetries <= SYNC_LOCK_RETRIES) {
|
||||
return;
|
||||
}
|
||||
if (isGrantError(err)) {
|
||||
status.login = false;
|
||||
}
|
||||
}
|
||||
status.lockRetries = 0;
|
||||
emitStatusChange();
|
||||
},
|
||||
};
|
||||
|
@ -208,6 +199,9 @@ const syncMan = (() => {
|
|||
setState(drive, state) {
|
||||
return chromeLocal.setValue(STORAGE_KEY + drive.name, state);
|
||||
},
|
||||
retryMaxAttempts: 10,
|
||||
retryExp: 1.2,
|
||||
retryDelay: 6,
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -257,8 +251,16 @@ const syncMan = (() => {
|
|||
function schedule(delay = SYNC_DELAY) {
|
||||
chrome.alarms.create('syncNow', {
|
||||
delayInMinutes: delay, // fractional values are supported
|
||||
periodInMinutes: SYNC_INTERVAL,
|
||||
});
|
||||
}
|
||||
|
||||
function translateErrorMessage(err) {
|
||||
if (err.name === 'LockError') {
|
||||
return browser.i18n.getMessage('syncErrorLock', new Date(err.expire).toLocaleString([], {timeStyle: 'short'}));
|
||||
}
|
||||
return err.message || String(err);
|
||||
}
|
||||
|
||||
//#endregion
|
||||
})();
|
||||
|
|
14
package-lock.json
generated
14
package-lock.json
generated
|
@ -10,7 +10,7 @@
|
|||
"license": "GPL-3.0-only",
|
||||
"dependencies": {
|
||||
"codemirror": "5.63.3",
|
||||
"db-to-cloud": "^0.6.0",
|
||||
"db-to-cloud": "^0.7.0",
|
||||
"jsonlint": "^1.6.3",
|
||||
"less-bundle": "github:openstyles/less-bundle#v0.1.0",
|
||||
"lz-string-unsafe": "^1.4.4-fork-1",
|
||||
|
@ -2322,9 +2322,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/db-to-cloud": {
|
||||
"version": "0.6.0",
|
||||
"resolved": "https://registry.npmjs.org/db-to-cloud/-/db-to-cloud-0.6.0.tgz",
|
||||
"integrity": "sha512-AbvxpU+fA3Fsdzu0OxL+cVPS9HwM6DzXFDg00WIQ3YeMkWs5saMXpiXMfISlkpBUwm5Cbr4W7cfhYszu38BzSw==",
|
||||
"version": "0.7.0",
|
||||
"resolved": "https://registry.npmjs.org/db-to-cloud/-/db-to-cloud-0.7.0.tgz",
|
||||
"integrity": "sha512-fs3FS6vMLk7E6gnuao9lJqTU+ohy6Pa9fqgZSVnoICMsCfqrnyYj+reA81xOmw9kfqVQNdtu+zZv67IJThrMvA==",
|
||||
"dependencies": {
|
||||
"@eight04/read-write-lock": "^0.1.0",
|
||||
"universal-base64": "^2.1.0"
|
||||
|
@ -11501,9 +11501,9 @@
|
|||
}
|
||||
},
|
||||
"db-to-cloud": {
|
||||
"version": "0.6.0",
|
||||
"resolved": "https://registry.npmjs.org/db-to-cloud/-/db-to-cloud-0.6.0.tgz",
|
||||
"integrity": "sha512-AbvxpU+fA3Fsdzu0OxL+cVPS9HwM6DzXFDg00WIQ3YeMkWs5saMXpiXMfISlkpBUwm5Cbr4W7cfhYszu38BzSw==",
|
||||
"version": "0.7.0",
|
||||
"resolved": "https://registry.npmjs.org/db-to-cloud/-/db-to-cloud-0.7.0.tgz",
|
||||
"integrity": "sha512-fs3FS6vMLk7E6gnuao9lJqTU+ohy6Pa9fqgZSVnoICMsCfqrnyYj+reA81xOmw9kfqVQNdtu+zZv67IJThrMvA==",
|
||||
"requires": {
|
||||
"@eight04/read-write-lock": "^0.1.0",
|
||||
"universal-base64": "^2.1.0"
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
},
|
||||
"dependencies": {
|
||||
"codemirror": "5.63.3",
|
||||
"db-to-cloud": "^0.6.0",
|
||||
"db-to-cloud": "^0.7.0",
|
||||
"jsonlint": "^1.6.3",
|
||||
"less-bundle": "github:openstyles/less-bundle#v0.1.0",
|
||||
"lz-string-unsafe": "^1.4.4-fork-1",
|
||||
|
|
2
vendor/db-to-cloud/README.md
vendored
2
vendor/db-to-cloud/README.md
vendored
|
@ -1,4 +1,4 @@
|
|||
## db-to-cloud v0.6.0
|
||||
## db-to-cloud v0.7.0
|
||||
|
||||
Following files are copied from npm (node_modules):
|
||||
|
||||
|
|
2
vendor/db-to-cloud/db-to-cloud.min.js
vendored
2
vendor/db-to-cloud/db-to-cloud.min.js
vendored
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user